From c51839da1bdabe2c708f62c355eb1a48f86566c1 Mon Sep 17 00:00:00 2001 From: Bjarte Johansen Date: Sat, 31 Aug 2013 10:06:51 +0200 Subject: [PATCH] optimalization move the atom-checking predicate last so it doesn't have to execute every time. --- src/sigmatism/pl/sigmatism.pl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sigmatism/pl/sigmatism.pl b/src/sigmatism/pl/sigmatism.pl index 32db248..01bc7fe 100644 --- a/src/sigmatism/pl/sigmatism.pl +++ b/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). @@ -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), @@ -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). @@ -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.