Skip to content

Commit

Permalink
format/1
Browse files Browse the repository at this point in the history
  • Loading branch information
infradig committed Nov 26, 2024
1 parent 97bda5c commit 450e8a1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
8 changes: 0 additions & 8 deletions library/builtins.pl
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,6 @@
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

format(F) :- format(F, []).

:- help(format(+string), [iso(false)]).

:- meta_predicate(not(0)).

not(X) :- X, !, fail.
Expand Down Expand Up @@ -413,10 +409,6 @@

:- help(writeln(+term), [iso(false)]).

format(stderr, F) :- format(stderr, F, []).

:- help(format(stderr, +term), [iso(false)]).

open(F, M, S) :- open(F, M, S, []).

:- help(open(+atom,+atom,--stream), [iso(true)]).
Expand Down
16 changes: 16 additions & 0 deletions src/bif_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,21 @@ bool do_format(query *q, cell *str, pl_idx str_ctx, cell *p1, pl_idx p1_ctx, cel
return true;
}

static bool bif_format_1(query *q)
{
GET_FIRST_ARG(p1,atom_or_list);
int n = q->pl->current_output;
stream *str = &q->pl->streams[n];

if (str->binary) {
cell tmp;
make_int(&tmp, n);
return throw_error(q, &tmp, q->st.curr_frame, "permission_error", "output,binary_stream");
}

return do_format(q, NULL, 0, p1, p1_ctx, NULL, q->st.curr_frame);
}

static bool bif_format_2(query *q)
{
GET_FIRST_ARG(p1,atom_or_list);
Expand Down Expand Up @@ -761,6 +776,7 @@ static bool bif_format_3(query *q)

builtins g_format_bifs[] =
{
{"format", 1, bif_format_1, "+string", false, false, BLAH},
{"format", 2, bif_format_2, "+string,+list", false, false, BLAH},
{"format", 3, bif_format_3, "+stream,+string,+list", false, false, BLAH},

Expand Down

0 comments on commit 450e8a1

Please sign in to comment.