diff --git a/src/lib/builtins.pl b/src/lib/builtins.pl index bea783f77..f4d9df79d 100644 --- a/src/lib/builtins.pl +++ b/src/lib/builtins.pl @@ -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, @@ -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'. @@ -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). @@ -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) :- @@ -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)) - ). diff --git a/src/lib/error.pl b/src/lib/error.pl index 67df8a32f..b6e685e32 100644 --- a/src/lib/error.pl +++ b/src/lib/error.pl @@ -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 ]). @@ -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)). diff --git a/src/lib/iso_ext.pl b/src/lib/iso_ext.pl index 5c779b10e..1af06cc52 100644 --- a/src/lib/iso_ext.pl +++ b/src/lib/iso_ext.pl @@ -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, @@ -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