Skip to content

Commit

Permalink
optimalization
Browse files Browse the repository at this point in the history
move the atom-checking predicate last so it doesn't have to execute
every time.
  • Loading branch information
ljos committed Aug 31, 2013
1 parent 92bbf46 commit c51839d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/sigmatism/pl/sigmatism.pl
@@ -1,5 +1,7 @@
char(C, [C|A], A) :-
char_type(C, alnum); char_type(C, period); char_type(C, quote).
char_type(C, alnum);
char_type(C, period);
char_type(C, quote).

chars([C]) --> char(C).
chars([C|Cs]) --> char(C), chars(Cs).
Expand Down Expand Up @@ -37,9 +39,6 @@
put_assoc(Key, Ns, Arg, Assoc),
pair(Keys, Args, Assoc, Namespace).

eval_lisp(AST, Ns, Value) :-
atom(AST),
get_assoc(AST, Ns, Value).
eval_lisp([quote, Q], _, Q).
eval_lisp([atom, A], Ns, t) :-
eval_lisp(A, Ns, Value),
Expand Down Expand Up @@ -71,13 +70,14 @@
eval_lisp([H | T], Ns, Value) :-
get_assoc(H, Ns, E),
eval_lisp([E | T], Ns, Value).
eval_lisp(AST, Ns, Value) :-
atom(AST),
get_assoc(AST, Ns, Value).

insert_space([H], [H]).
insert_space([H | T], [H, ' ' | R]) :-
insert_space(T, R).

writeln_lisp(L) :-
write_lisp(L), nl.
write_lisp(A) :-
atom(A),
write(A).
Expand All @@ -95,5 +95,5 @@
read_lisp(Chars, AST),
list_to_assoc([], Namespace),
eval_lisp(AST, Namespace, V),
writeln_lisp(V),
write_lisp(V), nl,
repl.

0 comments on commit c51839d

Please sign in to comment.