<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I must be to stupid to get it, unusually, I am pasting the entire source file as it stands along with the error message, I just don't get it. I just don't today, apologies for the long post of source code. I've tried re-reading the relevant parts of the documentation but it's just not sinking in, the language is too technically dry and formal for my uneducated brain.<div class=""><br class=""></div><div class="">SOURCE CODE:</div><div class=""><br class=""></div><div class=""><div class=""><div class="">➜ fbnf cat -n fbnf.m</div><div class=""> <font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 1<span class="Apple-tab-span" style="white-space:pre"> </span>%-----------------------------------------------------------------------------%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 2<span class="Apple-tab-span" style="white-space:pre"> </span>%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 3<span class="Apple-tab-span" style="white-space:pre"> </span>% File: fbnf.m</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 4<span class="Apple-tab-span" style="white-space:pre"> </span>% Main author: Sean Charles</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 5<span class="Apple-tab-span" style="white-space:pre"> </span>% Date: Sat Oct 1 19:48:26 2022</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 6<span class="Apple-tab-span" style="white-space:pre"> </span>%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 7<span class="Apple-tab-span" style="white-space:pre"> </span>% FORTH but not FORTH</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 8<span class="Apple-tab-span" style="white-space:pre"> </span>%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 9<span class="Apple-tab-span" style="white-space:pre"> </span>%-----------------------------------------------------------------------------%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 10<span class="Apple-tab-span" style="white-space:pre"> </span>:- module fbnf.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 11</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 12<span class="Apple-tab-span" style="white-space:pre"> </span>:- interface.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 13<span class="Apple-tab-span" style="white-space:pre"> </span>:- import_module io.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 14</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 15<span class="Apple-tab-span" style="white-space:pre"> </span>:- pred main(io::di, io::uo) is det.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 16</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 17</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 18<span class="Apple-tab-span" style="white-space:pre"> </span>:- implementation.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 19</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 20<span class="Apple-tab-span" style="white-space:pre"> </span>:- import_module bool.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 21<span class="Apple-tab-span" style="white-space:pre"> </span>:- import_module list.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 22<span class="Apple-tab-span" style="white-space:pre"> </span>:- import_module map.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 23<span class="Apple-tab-span" style="white-space:pre"> </span>:- import_module maybe.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 24<span class="Apple-tab-span" style="white-space:pre"> </span>:- import_module stack.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 25<span class="Apple-tab-span" style="white-space:pre"> </span>:- import_module string.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 26</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 27</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 28<span class="Apple-tab-span" style="white-space:pre"> </span>%----------------------------------------------------------------------------%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 29</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 30<span class="Apple-tab-span" style="white-space:pre"> </span>main(!IO) :-</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 31<span class="Apple-tab-span" style="white-space:pre"> </span> io.command_line_arguments(Args, !IO),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 32<span class="Apple-tab-span" style="white-space:pre"> </span> Arg = string.join_list(" ", Args),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 33<span class="Apple-tab-span" style="white-space:pre"> </span> io.format("ARG: %s\n", [s(Arg)], !IO),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 34</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 35<span class="Apple-tab-span" style="white-space:pre"> </span> ( if string.is_empty(Arg) then</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 36<span class="Apple-tab-span" style="white-space:pre"> </span> repl(initial_state, _, !IO)</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 37<span class="Apple-tab-span" style="white-space:pre"> </span> else</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 38<span class="Apple-tab-span" style="white-space:pre"> </span> interpret(string.words(Arg), initial_state, State1, !IO),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 39<span class="Apple-tab-span" style="white-space:pre"> </span> repl(State1, _, !IO)</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 40<span class="Apple-tab-span" style="white-space:pre"> </span> ).</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 41</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 42<span class="Apple-tab-span" style="white-space:pre"> </span>%----------------------------------------------------------------------------%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 43</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 44<span class="Apple-tab-span" style="white-space:pre"> </span>:- type lstr == list(string).</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 45</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 46<span class="Apple-tab-span" style="white-space:pre"> </span> % This is the WORD handler definition</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 47<span class="Apple-tab-span" style="white-space:pre"> </span> %</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 48<span class="Apple-tab-span" style="white-space:pre"> </span>%:- type word_handler == (pred(fstate, fstate, io, io, lstr, lstr)).</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 49<span class="Apple-tab-span" style="white-space:pre"> </span>%:- inst word_handler == (pred(in, out, di, uo, in, out)is det).</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 50</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 51<span class="Apple-tab-span" style="white-space:pre"> </span>:- type word_handler</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 52<span class="Apple-tab-span" style="white-space:pre"> </span> ---> word_handler(</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 53<span class="Apple-tab-span" style="white-space:pre"> </span> pred(</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 54<span class="Apple-tab-span" style="white-space:pre"> </span> fstate::in, fstate::out,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 55<span class="Apple-tab-span" style="white-space:pre"> </span> io::di, io::uo,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 56<span class="Apple-tab-span" style="white-space:pre"> </span> lstr::in, lstr::out) is det</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 57<span class="Apple-tab-span" style="white-space:pre"> </span> ).</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 58</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 59<span class="Apple-tab-span" style="white-space:pre"> </span>:- type word_map == map(string, word_handler).</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 60<span class="Apple-tab-span" style="white-space:pre"> </span>:- type stack_entry == stack(int).</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 61</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 62<span class="Apple-tab-span" style="white-space:pre"> </span> %</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 63<span class="Apple-tab-span" style="white-space:pre"> </span> % FBNF operating state</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 64<span class="Apple-tab-span" style="white-space:pre"> </span> %</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 65<span class="Apple-tab-span" style="white-space:pre"> </span>:- type fstate</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 66<span class="Apple-tab-span" style="white-space:pre"> </span> ---> fstate(</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 67<span class="Apple-tab-span" style="white-space:pre"> </span> fs_compiling :: bool,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 68<span class="Apple-tab-span" style="white-space:pre"> </span> fs_terminate :: bool,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 69<span class="Apple-tab-span" style="white-space:pre"> </span> fs_dict :: word_map,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 70<span class="Apple-tab-span" style="white-space:pre"> </span> fs_stack :: stack_entry,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 71<span class="Apple-tab-span" style="white-space:pre"> </span> fs_error :: maybe(string)</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 72<span class="Apple-tab-span" style="white-space:pre"> </span> ).</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 73</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 74</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 75<span class="Apple-tab-span" style="white-space:pre"> </span> % Create the initial state of the machine.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 76<span class="Apple-tab-span" style="white-space:pre"> </span> %</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 77<span class="Apple-tab-span" style="white-space:pre"> </span>:- func initial_state = (fstate::out) is det.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 78</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 79<span class="Apple-tab-span" style="white-space:pre"> </span>initial_state =</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 80<span class="Apple-tab-span" style="white-space:pre"> </span> fstate(</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 81<span class="Apple-tab-span" style="white-space:pre"> </span> no, % interpret mode</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 82<span class="Apple-tab-span" style="white-space:pre"> </span> no, % terminate requested ?</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 83<span class="Apple-tab-span" style="white-space:pre"> </span> initial_dictionary, % core words</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 84<span class="Apple-tab-span" style="white-space:pre"> </span> stack.init : stack_entry, % initial empty stack</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 85<span class="Apple-tab-span" style="white-space:pre"> </span> no % no error message</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 86<span class="Apple-tab-span" style="white-space:pre"> </span> ).</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 87</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 88</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 89<span class="Apple-tab-span" style="white-space:pre"> </span> % Create default system WORDS dictionary.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 90<span class="Apple-tab-span" style="white-space:pre"> </span> % Here we pre-load all the stock words that the user can build on</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 91<span class="Apple-tab-span" style="white-space:pre"> </span> % during the course of the session.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 92<span class="Apple-tab-span" style="white-space:pre"> </span> %</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 93<span class="Apple-tab-span" style="white-space:pre"> </span>:- func initial_dictionary = (word_map::out) is det.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 94</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 95<span class="Apple-tab-span" style="white-space:pre"> </span>initial_dictionary = Map :-</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 96<span class="Apple-tab-span" style="white-space:pre"> </span> some [!Words] (</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 97<span class="Apple-tab-span" style="white-space:pre"> </span> !:Words = map.init,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 98</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 99<span class="Apple-tab-span" style="white-space:pre"> </span> map.set(":", word_handler(define_word), !Words),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 100<span class="Apple-tab-span" style="white-space:pre"> </span> map.set("bye", word_handler(session_end), !Words),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 101<span class="Apple-tab-span" style="white-space:pre"> </span> map.set("words", word_handler(list_words), !Words),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 102</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 103<span class="Apple-tab-span" style="white-space:pre"> </span> Map = !.Words</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 104<span class="Apple-tab-span" style="white-space:pre"> </span> ).</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 105</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 106<span class="Apple-tab-span" style="white-space:pre"> </span>%----------------------------------------------------------------------------%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 107<span class="Apple-tab-span" style="white-space:pre"> </span>%----------------------------------------------------------------------------%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 108<span class="Apple-tab-span" style="white-space:pre"> </span>%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 109<span class="Apple-tab-span" style="white-space:pre"> </span>% System WORD Implementations</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 110<span class="Apple-tab-span" style="white-space:pre"> </span>%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 111<span class="Apple-tab-span" style="white-space:pre"> </span>%----------------------------------------------------------------------------%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 112<span class="Apple-tab-span" style="white-space:pre"> </span>%----------------------------------------------------------------------------%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 113</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 114<span class="Apple-tab-span" style="white-space:pre"> </span> % ":" - define a new word.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 115<span class="Apple-tab-span" style="white-space:pre"> </span> %</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 116<span class="Apple-tab-span" style="white-space:pre"> </span>:- pred define_word(fstate::in, fstate::out, io::di, io::uo,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 117<span class="Apple-tab-span" style="white-space:pre"> </span> lstr::in, lstr::out) is det.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 118</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 119<span class="Apple-tab-span" style="white-space:pre"> </span>define_word(!State, !IO) --></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 120<span class="Apple-tab-span" style="white-space:pre"> </span> {</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 121<span class="Apple-tab-span" style="white-space:pre"> </span> io.format("DEFINE WORD\n", [], !IO)</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 122<span class="Apple-tab-span" style="white-space:pre"> </span> }.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 123</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 124<span class="Apple-tab-span" style="white-space:pre"> </span> % "BYE" - terminate the current session.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 125<span class="Apple-tab-span" style="white-space:pre"> </span> %</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 126<span class="Apple-tab-span" style="white-space:pre"> </span>:- pred session_end(fstate::in, fstate::out, io::di, io::uo,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 127<span class="Apple-tab-span" style="white-space:pre"> </span> lstr::in, lstr::out) is det.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 128</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 129<span class="Apple-tab-span" style="white-space:pre"> </span>session_end(!State, !IO) --></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 130<span class="Apple-tab-span" style="white-space:pre"> </span> {</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 131<span class="Apple-tab-span" style="white-space:pre"> </span> io.format("BYE\n", [], !IO)</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 132<span class="Apple-tab-span" style="white-space:pre"> </span> }.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 133<span class="Apple-tab-span" style="white-space:pre"> </span> % "WORDS" - list all defined words.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 134<span class="Apple-tab-span" style="white-space:pre"> </span> %</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 135<span class="Apple-tab-span" style="white-space:pre"> </span>:- pred list_words(fstate::in, fstate::out, io::di, io::uo,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 136<span class="Apple-tab-span" style="white-space:pre"> </span> lstr::in, lstr::out) is det.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 137</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 138<span class="Apple-tab-span" style="white-space:pre"> </span>list_words(!State, !IO) --></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 139<span class="Apple-tab-span" style="white-space:pre"> </span> {</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 140<span class="Apple-tab-span" style="white-space:pre"> </span> io.format("WORDS\n", [], !IO)</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 141<span class="Apple-tab-span" style="white-space:pre"> </span> }.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 142</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 143<span class="Apple-tab-span" style="white-space:pre"> </span>%----------------------------------------------------------------------------%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 144</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 145<span class="Apple-tab-span" style="white-space:pre"> </span> % Read-Eval-Print-Loop</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 146<span class="Apple-tab-span" style="white-space:pre"> </span> %</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 147<span class="Apple-tab-span" style="white-space:pre"> </span>:- pred repl(fstate::in, fstate::out, io::di, io::uo) is det.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 148</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 149<span class="Apple-tab-span" style="white-space:pre"> </span>repl(!State, !IO) :-</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 150<span class="Apple-tab-span" style="white-space:pre"> </span> io.format("fbnf> ", [], !IO),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 151<span class="Apple-tab-span" style="white-space:pre"> </span> io.flush_output(!IO),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 152<span class="Apple-tab-span" style="white-space:pre"> </span> io.read_line_as_string(Res, !IO),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 153<span class="Apple-tab-span" style="white-space:pre"> </span> (</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 154<span class="Apple-tab-span" style="white-space:pre"> </span> Res = ok(Str),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 155<span class="Apple-tab-span" style="white-space:pre"> </span> interpret(string.words(Str), !State, !IO),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 156<span class="Apple-tab-span" style="white-space:pre"> </span> repl(!State, !IO)</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 157<span class="Apple-tab-span" style="white-space:pre"> </span> ;</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 158<span class="Apple-tab-span" style="white-space:pre"> </span> Res = error(Err),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 159<span class="Apple-tab-span" style="white-space:pre"> </span> io.format("error: %s\n", [s(io.error_message(Err))], !IO),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 160<span class="Apple-tab-span" style="white-space:pre"> </span> repl(!State, !IO)</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 161<span class="Apple-tab-span" style="white-space:pre"> </span> ;</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 162<span class="Apple-tab-span" style="white-space:pre"> </span> Res = eof,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 163<span class="Apple-tab-span" style="white-space:pre"> </span> io.format("Bye!\n", [], !IO)</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 164<span class="Apple-tab-span" style="white-space:pre"> </span> ).</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 165</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 166<span class="Apple-tab-span" style="white-space:pre"> </span>%----------------------------------------------------------------------------%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 167</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 168<span class="Apple-tab-span" style="white-space:pre"> </span>% from "Starting FORTH" ...</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 169<span class="Apple-tab-span" style="white-space:pre"> </span>%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 170<span class="Apple-tab-span" style="white-space:pre"> </span>% This will activate a word called INTERPRET, also known as the “text</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 171<span class="Apple-tab-span" style="white-space:pre"> </span>% interpreter.” The text interpreter scans the input stream, looking for strings</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 172<span class="Apple-tab-span" style="white-space:pre"> </span>% of characters separated by spaces. When a string is found, it is looked up in</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 173<span class="Apple-tab-span" style="white-space:pre"> </span>% the dictionary.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 174<span class="Apple-tab-span" style="white-space:pre"> </span>%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 175<span class="Apple-tab-span" style="white-space:pre"> </span>% If the word is in the dictionary, it is pointed out to a word called EXECUTE.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 176<span class="Apple-tab-span" style="white-space:pre"> </span>% EXECUTE executes the definition (in this case an asterisk is printed).</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 177<span class="Apple-tab-span" style="white-space:pre"> </span>% Finally, the interpreter says everything’s “ok.”</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 178</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 179<span class="Apple-tab-span" style="white-space:pre"> </span> % 'INTERPRET'</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 180<span class="Apple-tab-span" style="white-space:pre"> </span> % Process the current input stream of user tokens.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 181<span class="Apple-tab-span" style="white-space:pre"> </span> % If an error is detected then we abort the loop and abandon the input.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 182<span class="Apple-tab-span" style="white-space:pre"> </span> % Anything processed up to the error remains intact though this may or may</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 183<span class="Apple-tab-span" style="white-space:pre"> </span> % not lead to a safe state (TBD).</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 184<span class="Apple-tab-span" style="white-space:pre"> </span> %</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 185<span class="Apple-tab-span" style="white-space:pre"> </span>:- pred interpret(list(string)::in, fstate::in, fstate::out,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 186<span class="Apple-tab-span" style="white-space:pre"> </span> io::di, io::uo) is det.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 187</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 188<span class="Apple-tab-span" style="white-space:pre"> </span>interpret(Words, !State, !IO) :-</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 189<span class="Apple-tab-span" style="white-space:pre"> </span> compiling(no, !State),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 190<span class="Apple-tab-span" style="white-space:pre"> </span> interp1(Words, !State, !IO).</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 191</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 192</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 193<span class="Apple-tab-span" style="white-space:pre"> </span>:- pred interp1(list(string)::in, fstate::in, fstate::out,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 194<span class="Apple-tab-span" style="white-space:pre"> </span> io::di, io::uo) is det.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 195</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 196<span class="Apple-tab-span" style="white-space:pre"> </span>interp1([], !_, !_).</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 197</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 198<span class="Apple-tab-span" style="white-space:pre"> </span>interp1([W|Ws], !State, !IO) :-</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 199<span class="Apple-tab-span" style="white-space:pre"> </span> io.format("interp1: %s\n", [s(W)], !IO),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 200<span class="Apple-tab-span" style="white-space:pre"> </span> execute(W, Ws, Rest, !State, !IO),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 201<span class="Apple-tab-span" style="white-space:pre"> </span> flush_error(HadError, !State, !IO),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 202<span class="Apple-tab-span" style="white-space:pre"> </span> ( if HadError = yes then</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 203<span class="Apple-tab-span" style="white-space:pre"> </span> true % abandon ship.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 204<span class="Apple-tab-span" style="white-space:pre"> </span> else</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 205<span class="Apple-tab-span" style="white-space:pre"> </span> interp1(Rest, !State, !IO)</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 206<span class="Apple-tab-span" style="white-space:pre"> </span> ).</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 207</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 208<span class="Apple-tab-span" style="white-space:pre"> </span> % 'EXECUTE'</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 209<span class="Apple-tab-span" style="white-space:pre"> </span> % Find the word in the dictionary so we can invoke it, if it's not</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 210<span class="Apple-tab-span" style="white-space:pre"> </span> % found we want to record the error and terminate processing.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 211<span class="Apple-tab-span" style="white-space:pre"> </span> %</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 212<span class="Apple-tab-span" style="white-space:pre"> </span>:- pred execute(string::in, list(string)::in, list(string)::out,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 213<span class="Apple-tab-span" style="white-space:pre"> </span> fstate::in, fstate::out, io::di, io::uo) is det.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 214</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 215<span class="Apple-tab-span" style="white-space:pre"> </span>execute(Word, Words, Rest, !State, !IO) :-</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 216<span class="Apple-tab-span" style="white-space:pre"> </span> Dict = fs_dict(!.State),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 217<span class="Apple-tab-span" style="white-space:pre"> </span> ( if map.search(Dict, Word, word_handler(Entry)) then</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 218<span class="Apple-tab-span" style="white-space:pre"> </span> Entry(!State, !IO)</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 219<span class="Apple-tab-span" style="white-space:pre"> </span> else</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 220<span class="Apple-tab-span" style="white-space:pre"> </span> set_error(string.format("word not found: %s\n",</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 221<span class="Apple-tab-span" style="white-space:pre"> </span> [s(Word)]), !State)</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 222<span class="Apple-tab-span" style="white-space:pre"> </span> ),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 223<span class="Apple-tab-span" style="white-space:pre"> </span> Rest = Words.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 224</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 225<span class="Apple-tab-span" style="white-space:pre"> </span>%----------------------------------------------------------------------------%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 226<span class="Apple-tab-span" style="white-space:pre"> </span>%----------------------------------------------------------------------------%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 227<span class="Apple-tab-span" style="white-space:pre"> </span>%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 228<span class="Apple-tab-span" style="white-space:pre"> </span>% STATE change operations</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 229<span class="Apple-tab-span" style="white-space:pre"> </span>%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 230<span class="Apple-tab-span" style="white-space:pre"> </span>%----------------------------------------------------------------------------%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 231<span class="Apple-tab-span" style="white-space:pre"> </span>%----------------------------------------------------------------------------%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 232</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 233<span class="Apple-tab-span" style="white-space:pre"> </span> % Set 'compiling' mode as indicated.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 234<span class="Apple-tab-span" style="white-space:pre"> </span> %</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 235<span class="Apple-tab-span" style="white-space:pre"> </span>:- pred compiling(bool::in, fstate::in, fstate::out) is det.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 236</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 237<span class="Apple-tab-span" style="white-space:pre"> </span>compiling(Mode, !State) :-</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 238<span class="Apple-tab-span" style="white-space:pre"> </span> !:State = !.State ^fs_compiling := Mode.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 239</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 240<span class="Apple-tab-span" style="white-space:pre"> </span>:- func is_compiling(fstate::in) = (bool::out) is det.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 241</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 242<span class="Apple-tab-span" style="white-space:pre"> </span>is_compiling(S) = S ^fs_compiling.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 243</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 244</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 245<span class="Apple-tab-span" style="white-space:pre"> </span> % Set an error message into the state.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 246<span class="Apple-tab-span" style="white-space:pre"> </span> %</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 247<span class="Apple-tab-span" style="white-space:pre"> </span>:- pred set_error(string::in, fstate::in, fstate::out) is det.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 248</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 249<span class="Apple-tab-span" style="white-space:pre"> </span>set_error(Message, !State) :-</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 250<span class="Apple-tab-span" style="white-space:pre"> </span> !:State = !.State ^fs_error := yes(Message).</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 251</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 252<span class="Apple-tab-span" style="white-space:pre"> </span> % Flush (by writing) the current error message.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 253<span class="Apple-tab-span" style="white-space:pre"> </span> % Flushed will be 'yes' if there was an error in the state record</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 254<span class="Apple-tab-span" style="white-space:pre"> </span> % and this will cause the current processing to abort.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 255<span class="Apple-tab-span" style="white-space:pre"> </span> %</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 256<span class="Apple-tab-span" style="white-space:pre"> </span>:- pred flush_error(bool::out, fstate::in, fstate::out, io::di, io::uo) is det.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 257</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 258<span class="Apple-tab-span" style="white-space:pre"> </span>flush_error(Flushed, !State, !IO) :-</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 259<span class="Apple-tab-span" style="white-space:pre"> </span> (if yes(Error) = !.State ^ fs_error then</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 260<span class="Apple-tab-span" style="white-space:pre"> </span> io.format("error: %s\n", [s(Error)], !IO),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 261<span class="Apple-tab-span" style="white-space:pre"> </span> Flushed = yes</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 262<span class="Apple-tab-span" style="white-space:pre"> </span> else</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 263<span class="Apple-tab-span" style="white-space:pre"> </span> Flushed = no</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 264<span class="Apple-tab-span" style="white-space:pre"> </span> ).</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 265</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 266<span class="Apple-tab-span" style="white-space:pre"> </span>%----------------------------------------------------------------------------%</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 267<span class="Apple-tab-span" style="white-space:pre"> </span>:- end_module fbnf.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> 268<span class="Apple-tab-span" style="white-space:pre"> </span>%----------------------------------------------------------------------------%</span></font></div></div><div class=""><br class=""></div><div class="">ERROR OUTPUT:</div><div class=""><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">➜ fbnf cat fbnf.err</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: In clause for predicate `execute'/7:</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: in argument 1 (i.e. the predicate term) of higher-order predicate</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: call:</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: type error: variable `Entry' has type</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: `pred(</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: fbnf.fstate :: builtin.in,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: fbnf.fstate :: builtin.out,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: io.state :: builtin.di,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: io.state :: builtin.uo,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: list.list(string) :: builtin.in,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: list.list(string) :: builtin.out</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: ) is det',</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: expected type was</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: `pred(</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: V_7,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: V_8,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: V_9,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: V_10</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: )'.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: The partial type assignment was:</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: Word_8: string</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: Words_9: list.list(string)</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: Rest_10: list.list(string)</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: Dict_13: tree234.tree234(string, fbnf.word_handler)</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: Entry_14: (pred((fbnf.fstate :: builtin.in), (fbnf.fstate ::</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: builtin.out), (io.state :: builtin.di), (io.state ::</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: builtin.uo), (list.list(string) :: builtin.in),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: (list.list(string) :: builtin.out)) is det)</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: STATE_VARIABLE_State_0_15: fbnf.fstate</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: STATE_VARIABLE_State_16: fbnf.fstate</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: STATE_VARIABLE_IO_0_17: io.state</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: STATE_VARIABLE_IO_18: io.state</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">fbnf.m:218: V_19: fbnf.word_handler</span></font></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">It's basically the same error I had last time via a different route as far as my limited brain can tell. Some days this higher-order stuff just makes no sense to me at all how Mercury does it.</div><div class=""><br class=""></div><div class="">Sorry.</div><div class=""><br class=""></div><div><br class=""><blockquote type="cite" class=""><div class="">On 5 Oct 2022, at 08:59, Sean Charles (emacstheviking) <<a href="mailto:objitsu@gmail.com" class="">objitsu@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Thanks Julien, I will try that.<br class=""><br class="">About the state vars/DCG... yes, I don't like it either and today I am going to remove the DCG style... I am such an old Prolog stalwart that sometimes I do it without realising it! :D And my brain isn't 100% yet; as I told Volker, I recently had 70% of my liver removed (cancer) and the resulting brain fog has been, shall we say, amusing to observe and very frustrating to live with, but it gets clearer ever day now.<br class=""><br class="">I do remember a post from Volker a long time ago on a very similar matter but try as I might I just couldn't find it for reference.<br class=""><br class="">Thanks again,<br class="">Sean.<br class=""><br class=""><br class=""><blockquote type="cite" class="">On 5 Oct 2022, at 04:25, Julien Fischer <<a href="mailto:jfischer@opturion.com" class="">jfischer@opturion.com</a>> wrote:<br class=""><br class=""><br class="">Hi,<br class=""><br class="">On Tue, 4 Oct 2022, Sean Charles (emacstheviking) wrote:<br class=""><br class=""><blockquote type="cite" class="">I am fleshing out a VERY loose forth type system, I have the following definitions to allow me to set up a map of word names and there handlers:<br class="">:- type lstr == list(string).<br class="">:- type word_handler == (pred(fstate, fstate, io, io, lstr, lstr)).<br class="">:- inst word_handler == (pred(in, out, di, uo, in, out)is det).<br class="">:- type word_map == map(string, word_handler).<br class="">:- type stack_entry == stack(int).<br class=""></blockquote><br class="">As Volker mentioned, this won't work as the inst of nearly every output<br class="">argument in the map module is ground and the higher-order inst will be<br class="">lost.<br class=""><br class="">An alternative would be to use combined higher-order types and insts and<br class="">define the word_handler type as:<br class=""><br class=""> :- type word_handler<br class=""> ---> word_handler(pred(fstate::in, fstate::out, io::di, io::uo, lstr::in, lstr::out) is det).<br class=""><br class="">That should do what you want with fairly minimal changes elsewhere<br class="">(mainly accounting for the the word_handler wrapper that is now around<br class="">the higher-order term).<br class=""><br class="">...<br class=""><br class=""><blockquote type="cite" class="">I am not sure the DCG style will remain but it's pure proof of concept / exploratory at the moment.<br class=""></blockquote><br class="">IMO, mixing DCGs and state variables like that looks weird.<br class=""><br class="">Julien.<br class=""></blockquote><br class=""></div></div></blockquote></div><br class=""></div></div></body></html>