SWIProlog
This commit is contained in:
Executable
BIN
Binary file not shown.
@@ -103,20 +103,18 @@ assert_def(Symbol, Body) :-
|
||||
foo(Var, Name=Var) :- gensym('A', Name).
|
||||
|
||||
|
||||
barzs([], []).
|
||||
barzs([Var|Bs], [(Name=Var)|Ls]) :-
|
||||
names_for_variables([], []).
|
||||
names_for_variables([Var|Bs], [(Name=Var)|Ls]) :-
|
||||
gensym('A', Name),
|
||||
barzs(Bs, Ls).
|
||||
names_for_variables(Bs, Ls).
|
||||
|
||||
main :-
|
||||
read_term(Expression, []),
|
||||
thun(Expression, Si, So),
|
||||
term_variables((Si, So), L),
|
||||
barzs(L, LL),
|
||||
%write_canonical(LL), writeln(""),
|
||||
write_term(Si, [quoted(true),fullstop(true),variable_names(LL)]),
|
||||
write_term(So, [quoted(true),fullstop(true),variable_names(LL)]),
|
||||
writeln("").
|
||||
term_variables((Si, So), Vars),
|
||||
names_for_variables(Vars, Names),
|
||||
write_term(Si, [quoted(true),variable_names(Names)]), writeln(","),
|
||||
write_term(So, [quoted(true),variable_names(Names)]), writeln("").
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
[symbol(clear),list([symbol(base),int(2147483648)])].
|
||||
@@ -34,8 +34,15 @@ joy_term(list(J)) --> [lbracket], !, joy_parse(J), [rbracket].
|
||||
joy_term(Token) --> [tok(Codes)], {joy_token(Token, Codes)}.
|
||||
|
||||
joy_token(int(I), Codes) :- catch(number_codes(I, Codes), _Err, fail), !.
|
||||
joy_token(bool(true), "true") :- !.
|
||||
joy_token(bool(false), "false") :- !.
|
||||
% Leaving the literals below as "true" and "false" caused those
|
||||
% to be encoded as symbols instead of bools! I tried '--traditional'
|
||||
% but then compilation failed with
|
||||
% > ERROR: atomics_to_string/3: Type error: `text' expected, found `[61]' (a list)
|
||||
% Which was less helpful than it sounds.
|
||||
% Anyway, since this is SWI-specific code anyway, why not use ``'s and get on with life?
|
||||
% https://www.swi-prolog.org/pldoc/man?section=string
|
||||
joy_token(bool(true), `true`) :- !.
|
||||
joy_token(bool(false), `false`) :- !.
|
||||
joy_token(symbol(S), Codes) :- atom_codes(S, Codes).
|
||||
|
||||
text_to_expression(Text, Expression) :-
|
||||
|
||||
Reference in New Issue
Block a user