Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 3 additions & 35 deletions src/lib/builtins.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
at_end_of_stream/0, at_end_of_stream/1,
atom_chars/2, atom_codes/2, atom_concat/3,
atom_length/2, bagof/3, call/1, call/2, call/3,
call/4, call/5, call/6, call/7, call/8, call/9,
call/4, call/5, call/6, call/7, call/8,
callable/1, catch/3, char_code/2, clause/2,
close/1, close/2, current_input/1,
current_output/1, current_op/3,
current_predicate/1, current_prolog_flag/2,
error/2, fail/0, false/0, findall/3, findall/4,
fail/0, false/0, findall/3,
flush_output/0, flush_output/1, get_byte/1,
get_byte/2, get_char/1, get_char/2, get_code/1,
get_code/2, halt/0, halt/1, nl/0, nl/1,
Expand Down Expand Up @@ -53,7 +53,7 @@
false :- '$fail'.


% These are stub versions of call/{1-9} defined for bootstrapping.
% These are stub versions of call/{1-8} defined for bootstrapping.
% Once Scryer is bootstrapped, each is replaced with a version that
% uses expand_goal to pass the expanded goal along to '$call'.

Expand Down Expand Up @@ -106,12 +106,6 @@
% appended to the argument list.
call(_, _, _, _, _, _, _, _).

%% call(Goal, ExtraArg1, ExtraArg2, ExtraArg3, ExtraArg4, ExtraArg5, ExtraArg6, ExtraArg7, ExtraArg8).
%
% Execute Goal with ExtraArg1, ExtraArg2, ExtraArg3, ExtraArg4, ExtraArg5, ExtraArg6, ExtraArg7 and
% ExtraArg8, appended to the argument list.
call(_, _, _, _, _, _, _, _, _).


:- meta_predicate catch(0, ?, 0).

Expand Down Expand Up @@ -927,23 +921,6 @@
'$get_lh_from_offset_diff'(LhOffset, Solutions0, Solutions1).


:- meta_predicate findall(?, 0, ?, ?).

:- non_counted_backtracking findall/4.

%% findall(Template, Goal, Solutions0, Solutions1)
%
% Similar to `findall/3` but returns the solutions as the difference list Solutions0-Solutions1.
findall(Template, Goal, Solutions0, Solutions1) :-
error:can_be(list, Solutions0),
error:can_be(list, Solutions1),
'$lh_length'(LhLength),
catch(builtins:'$iterate_find_all_diff'(Template, Goal, Solutions0,
Solutions1, LhLength),
Error,
builtins:findall_cleanup(LhLength, Error)
).

:- non_counted_backtracking set_difference/3.

set_difference([X|Xs], [Y|Ys], Zs) :-
Expand Down Expand Up @@ -2241,12 +2218,3 @@
% Writes a new line character to the stream Stream.
nl(Stream) :-
put_char(Stream, '\n').

%% error(ErrorTerm, ImpDef).
%
% Throws an exception of the following structure: `error(ErrorTerm, ImpDef)`.
error(Error_term, Imp_def) :-
( var(Error_term) ->
throw(error(instantiation_error, error/2))
; throw(error(Error_term, Imp_def))
).
12 changes: 11 additions & 1 deletion src/lib/error.pl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
instantiation_error/1,
domain_error/3,
type_error/3,
call_with_error_context/2
call_with_error_context/2,
error/2
]).


Expand Down Expand Up @@ -217,6 +218,15 @@
Shorthands for throwing ISO errors.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

%% error(ErrorTerm, ImpDef).
%
% Throws an exception of the following structure: `error(ErrorTerm, ImpDef)`.
error(Error_term, Imp_def) :-
( var(Error_term) ->
throw(error(instantiation_error, error/2))
; throw(error(Error_term, Imp_def))
).

instantiation_error(Context) :-
throw(error(instantiation_error, Context)).

Expand Down
19 changes: 19 additions & 0 deletions src/lib/iso_ext.pl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
call_with_inference_limit/3,
call_residue_vars/2,
forall/2,
findall/4,
partial_string/1,
partial_string/3,
partial_string_tail/2,
Expand Down Expand Up @@ -381,6 +382,24 @@
; true
)).

%% findall(Template, Goal, Solutions0, Solutions1)
%
% Similar to `findall/3` but returns the solutions as the difference list Solutions0-Solutions1.

:- meta_predicate findall(?, 0, ?, ?).

:- non_counted_backtracking findall/4.

findall(Template, Goal, Solutions0, Solutions1) :-
error:can_be(list, Solutions0),
error:can_be(list, Solutions1),
'$lh_length'(LhLength),
catch(builtins:'$iterate_find_all_diff'(Template, Goal, Solutions0,
Solutions1, LhLength),
Error,
builtins:findall_cleanup(LhLength, Error)
).

%% copy_term_nat(Source, Dest)
%
% Similar to `copy_term/2` but without attribute variables
Expand Down