Merge branch 'master' into library-use-case

This commit is contained in:
Nicolas Luck
2024-02-09 12:41:01 +01:00
8 changed files with 160 additions and 24 deletions

View File

@@ -20,6 +20,7 @@ read and write chars.
:- use_module(library(iso_ext)).
:- use_module(library(error)).
:- use_module(library(lists)).
:- use_module(library(between)).
:- use_module(library(iso_ext), [partial_string/1,partial_string/3]).
fabricate_var_name(VarType, VarName, N) :-
@@ -74,9 +75,10 @@ extend_var_list_([V|Vs], N, VarList, NewVarList, VarType) :-
).
%% char_type(+Char, -Type).
%% char_type(?Char, ?Type).
%
% Given a Char, Type is one of the categories that char fits in.
% Type is one of the categories that Char fits in.
% At least one of the arguments must be ground.
% Possible categories are:
%
% - `alnum`
@@ -132,17 +134,32 @@ extend_var_list_([V|Vs], N, VarList, NewVarList, VarType) :-
% Note that uppercase and lowercase transformations use a string. This is because
% some characters do not map 1:1 between lowercase and uppercase.
char_type(Char, Type) :-
must_be(character, Char),
( ground(Type) ->
( ctype(Type) ->
'$char_type'(Char, Type)
; domain_error(char_type, Type, char_type/2)
)
; ctype(Type),
can_be(character, Char),
( \+ ctype(Type) ->
domain_error(char_type, Type, char_type/2)
; true
),
( ground(Char) ->
ctype(Type),
'$char_type'(Char, Type)
; ground(Type) ->
max_char_code(Max),
between(0, Max, Code),
char_code(Char, Code),
'$char_type'(Char, Type)
; must_be(character, Char)
).
max_char_code(Max) :-
catch((length(_, Code),
catch(char_code(_Char, Code),
error(representation_error(_),_),
throw(max_char_code(Code))),
false),
max_char_code(Code),
Max is Code - 1).
ctype(alnum).
ctype(alpha).
ctype(alphabetic).

View File

@@ -102,6 +102,7 @@
fd_dom/2,
% for use in predicates from library(reif)
clpz_t/2,
(#=)/3,
(#<)/3
@@ -7981,13 +7982,13 @@ coeff_var_term(C-V, T) :- ( C =:= 1 -> T = #V ; T = C * #V ).
Reified predicates for use with predicates from library(reif).
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#=(X, Y, T) :-
X #= Y #<==> #B,
clpz_t(Expr, T) :-
Expr #<==> #B,
zo_t(B, T).
#<(X, Y, T) :-
X #< Y #<==> #B,
zo_t(B, T).
#=(X, Y, T) :- clpz_t(X #= Y, T).
#<(X, Y, T) :- clpz_t(X #< Y, T).
zo_t(0, false).
zo_t(1, true).

View File

@@ -221,7 +221,7 @@ row([X | Y], Opt) -->
!,
( separator(Opt) ->
row(Y, Opt)
; end_token ->
; end_token,
{ Y = [] }).

View File

@@ -40,23 +40,36 @@ load_scryerrc :-
(\+ disabled_init_file -> load_scryerrc ; true),
repl.
args_consults_goals([], [], []).
args_consults_goals([Arg|Args], Consults, Goals) :-
arg_consults_goals(Arg, Args, Consults, Goals).
arg_consults_goals(c(Mod), Args, [c(Mod)|Consults], Goals) :-
args_consults_goals(Args, Consults, Goals).
arg_consults_goals(g(Goal), Args, Consults, [g(Goal)|Goals]) :-
args_consults_goals(Args, Consults, Goals).
delegate_task([], []).
delegate_task([], Goals0) :-
reverse(Goals0, Goals),
(\+ disabled_init_file -> load_scryerrc ; true),
reverse(Goals0, Goals1),
args_consults_goals(Goals1, Consults, Goals),
run_goals(Consults),
run_goals(Goals),
repl.
delegate_task([Arg0|Args], Goals0) :-
( member(Arg0, ["-h", "--help"]) -> print_help
; member(Arg0, ["-v", "--version"]) -> print_version
; member(Arg0, ["-g", "--goal"]) -> gather_goal(g, Args, Goals0)
; member(Arg0, ["-f"]) -> disable_init_file
; member(Arg0, ["--no-add-history"]) -> ignore_machine_arg
( ( member(Arg0, ["-h", "--help"]) -> print_help
; member(Arg0, ["-v", "--version"]) -> print_version
; member(Arg0, ["-g", "--goal"]) -> gather_goal(g, Args, Goals0)
; member(Arg0, ["-f"]) -> disable_init_file
; member(Arg0, ["--no-add-history"]) -> ignore_machine_arg
),
!,
delegate_task(Args, Goals0)
; atom_chars(Mod, Arg0),
catch(consult(Mod), E, print_exception(E))
),
delegate_task(Args, Goals0).
delegate_task(Args, [c(Mod)|Goals0])
).
print_help :-
write('Usage: scryer-prolog [OPTIONS] [FILES] [-- ARGUMENTS]'),
@@ -96,6 +109,7 @@ ignore_machine_arg.
arg_type(g).
arg_type(t).
arg_type(c(_)).
arg_type(g(_)).
arg_type(t(_)).
@@ -132,6 +146,14 @@ run_goals([g(Gs0)|Goals]) :- !,
write_term(Goal, [variable_names(VNs),double_quotes(DQ)]), nl
),
run_goals(Goals).
run_goals([c(Mod)|Goals]) :- !,
( catch(consult(Mod), E, print_exception(E)) ->
true
; write('% Warning: initialization failed for: '),
double_quotes_option(DQ),
write_term(consult(Mod), [double_quotes(DQ)]), nl
),
run_goals(Goals).
run_goals([Goal|_]) :-
loader:write_error(error(domain_error(arg_type, Goal), run_goals/1)),
nl,