1

I know that I can use variables in Prolog shell (something like using '$' character, I think...but I don't remember...)

If I execute the following query it seems to work fine:

?- 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(..., ...)|...] 

But if I try to execute the two query leggiFile/2 and tokenizzaLista/2 separately, in this way go into error:

?- leggiFile('dataggare.txt', ListaTesto).
ListaTesto = [68, 117, 114, 97, 110, 116, 101, 32, 105|...].

?- tokenizzaLista($ListaTesto, TokenizedList, 1).
ERROR: variable `ListaTesto' does not exist

Why? it seems to me very strange. What am I missing?

false
  • 10,264
  • 13
  • 101
  • 209
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
  • if tokenizzaLista is DCG based, you can use phrase_from_file – CapelliC May 24 '13 at 15:55
  • no, this is not a DCG based – AndreaNobili May 24 '13 at 16:17
  • `$` is not guaranteed to work always. It is intended as a quick hack (for a user). The proper way is simply to `asserta` it into the database under a functor name of your choosing: e.g. `asserta( sym(Name,Val) )` and then `sym(Name,Val)` to retrieve. – Will Ness May 25 '13 at 08:12

1 Answers1

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])).
...

but I'm not sure if garbage collection could disturb...

Documentation states

Bindings resulting from the successful execution of a top-level goal are asserted in a database if they are not too large.

CapelliC
  • 59,646
  • 5
  • 47
  • 90
  • I have change my question because I had made a series of errors in the original one. Still don't work but now I have post the real problem...it seems to me strange because I think that I am using the correct syntax to use variables in Prolog shell – AndreaNobili May 24 '13 at 15:48
  • 1
    I think your variables are too large. – CapelliC May 24 '13 at 15:52
  • maybe this is the reason because ListaTesto contains all the ASCII character of a txt file...I will try with a very short file – AndreaNobili May 24 '13 at 16:18