<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" 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:<div class=""><br class=""></div><div class=""><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">:- type lstr == list(string).</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""><br class=""></span></font></div><div class=""><span style="font-family: "Andale Mono";" class="">:- type word_handler == (pred(fstate, fstate, io, io, lstr, lstr)).</span></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">:- 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=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">:- type word_map == map(string, word_handler).</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">:- type stack_entry == stack(int).</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> %</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> % FBNF operating state</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> %</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">:- type fstate</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> ---> fstate(</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> fs_dict :: word_map,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> fs_stack :: stack_entry,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> fs_error :: maybe(string)</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> ).</span></font></div><div class=""><br class=""></div><div class="">then I initialise the default word list like this:</div><div class=""><br class=""></div><div class=""><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">initial_dictionary = Map :-</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> some [!Words] (</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> !:Words = map.init,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> map.set(":", define_word, !Words),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> map.set("words", list_words, !Words),</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> Map = !.Words</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> ).</span></font></div></div><div class=""><br class=""></div><div class="">Here are the implementations of the above two default words:</div><div class=""><br class=""></div><div class=""><div class=""><span style="font-family: "Andale Mono";" class="">:- pred define_word(fstate::in, fstate::out, io::di, io::uo,</span></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> lstr::in, lstr::out) is det.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">define_word(!State, !IO) --></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> {</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> io.format("DEFINE WORD\n", [], !IO)</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> }.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""><br class=""></span></font></div><div class=""><span style="font-family: "Andale Mono";" class=""><br class=""></span></div><div class=""><span style="font-family: "Andale Mono";" class="">:- pred list_words(fstate::in, fstate::out, io::di, io::uo,</span></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> lstr::in, lstr::out) is det.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">list_words(!State, !IO) --></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> {</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> io.format("WORDS\n", [], !IO)</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> }.</span></font></div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">and eventually when I try to call it, I get the error on the line shown , here I look up the word in the map into Entry, and try to call it:</div><div class=""><br class=""></div><div class=""><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">:- pred execute(string::in, fstate::in, fstate::out, io::di, io::uo,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> lstr::in, lstr::out) is det.</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">execute(Word, !State, !IO) --></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> { Words = fs_dict(!.State) },</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> ( if { map.search(Words, Word, Entry) } then</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class="">(191) Entry(!State, !IO) <====== compiler hate this line!</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> else</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> { set_error(</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> string.format("word not found: %s\n",</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> [s(Word)]), !State) }</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style: normal;" class=""> ).</span></font></div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class="">fbnf.m:191: In clause for `execute(in, in, out, di, uo, in, out)':</div><div class="">fbnf.m:191: in argument 1 (i.e. the predicate term) of higher-order predicate</div><div class="">fbnf.m:191: call:</div><div class="">fbnf.m:191: mode error: variable `Entry' has instantiatedness `ground',</div><div class="">fbnf.m:191: expecting higher-order pred inst of arity 6.</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I am not sure the DCG style will remain but it's pure proof of concept / exploratory at the moment. I used getopt.m as inspiration but obviously talent and brains are needed as well... what have I not told the compiler that it needs to know ?</div><div class=""><br class=""></div><div class="">Thanks</div><div class="">Sean</div><div class=""><br class=""></div></div></body></html>