我知道我可以在Prolog shell中使用变量(类似于使用'$'字符,我想......但我不记得......)
如果我执行以下查询,它似乎工作正常:
?- leggiFile('dataggare.txt', ListaTesto), tokenizzaLista(ListaTesto, TokenizedList, 1).
ListaTesto = [68, 117, 114, 97, 110, 116, 101, 32, 105|...],
TokenizedList = [t(1, [68, 117, 114, 97, 110, 116, 101]), t(-1, [32]), t(2, [105, 108]), t(-1, [32]), t(3, [77, 101, 100|...]), t(-1, [44]), t(-1, [32]), t(4, [...|...]), t(..., ...)|...]
但如果我尝试分别执行两个查询 leggiFile / 2 和 tokenizzaLista / 2 ,就会出错:
?- leggiFile('dataggare.txt', ListaTesto).
ListaTesto = [68, 117, 114, 97, 110, 116, 101, 32, 105|...].
?- tokenizzaLista($ListaTesto, TokenizedList, 1).
ERROR: variable `ListaTesto' does not exist
为什么呢?在我看来很奇怪。我错过了什么?
答案 0 :(得分:1)
?- open('uty.pl',read,S).
S = <stream>(0x236d4d0).
?- read($S,K).
K = (:-module(uty, [atoi//2, cache_file/2, cache_path/4, call_nth/2, cat/2, count_solutions/2, ... / ...|...])).
?- read($S,K).
K = (:-reexport(nb_uty, [ (<<)/2, (>>)/2, ++ / 2, (**)/2])).
...
但我不确定垃圾收集是否会打扰......
如果它们不是太大,则在数据库中声明由成功执行顶级目标而产生的绑定。