From c1442945a6e1d190854cc534bdcf1e9327e25c84 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Sun, 21 Jul 2019 14:13:48 -0700 Subject: [PATCH] Assert definitions as they are read. Instead of building a list then asserting them all after parsing. --- thun/thun.pl | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/thun/thun.pl b/thun/thun.pl index 5717c31..b611059 100644 --- a/thun/thun.pl +++ b/thun/thun.pl @@ -186,16 +186,12 @@ Definitions joy_def(def(Def, Body)) --> symbol(Def), blanks, "==", joy_parse(Body). -joy_defs([Def|Defs]) --> blanks, joy_def(Def), blanks, joy_defs(Defs). -joy_defs([]) --> []. - -read_defs(DefsFile, Defs) :- - read_file_to_codes(DefsFile, Codes, []), - phrase(joy_defs(Defs), Codes). +joy_defs --> blanks, joy_def(Def), {assert_def(Def)}, blanks, joy_defs. +joy_defs --> []. assert_defs(DefsFile) :- - read_defs(DefsFile, Defs), - forall(member(Def, Defs), assert_def(Def)). + read_file_to_codes(DefsFile, Codes, []), + phrase(joy_defs, Codes). assert_def(def(Def, Body)) :- retractall(def(Def, _)),