Try using single quotes rather than the double quotes. This allows an atom to be formed using varied characters besides the default syntax for an atom.
Double quotes turn the contents into a list of characters, as you've seen above.
> The message is saying that it expects an atom where it gets something else. > And that it is in the open/3 predicate. > That should ring a bell, no ?
> Replace the " by '
> Cheers
> Bart Demoen
Thanks for the comments. I wasn't aware of the differences between ' and "
You just highlighted my ignorance of the Prolog type system. (I know, Prolog is called untyped. )
> The message is saying that it expects an atom where it gets something else. > And that it is in the open/3 predicate. > That should ring a bell, no ?
> Replace the " by '
> Cheers
> Bart Demoen
Another problem: it doesn't find the file (although I checked, it's there). I even tried using double blackslahses, but I got:
ERROR: seeing/1: Domain error: `stream' expected, found `C:\Documents and Settings\Levente\My Documents\parse.pl'
I even tried to change "\" to "/".
The current version of my code looks like:
fussal(X):- X = 'C:\Documents and Settings\Levente\My Documents\parse.pl', see(X), seeing(X), read(T),display(T).
I fixed my program. I copy it hereby for the benefit of my fellow noobs:
fussal(X):- X = 'c:/parse.pl', see(X), % This will give an error, because it expects a stream; % seeing(X), repeat, get_char(T),print(T),T=end_of_file,!,seen.
The conclusions: 1, If you omit the "seen" from the end of the end of the last line, the next time you run the program you'll experience that the program only reads "end_of_file" signs. This is because the "cursor position" of file reading is assigned to the opened stream. (And a stream acts like a global variable.)
2, read/1 is for parsing prolog files. (It can handle the DCG syntax as well.)
> I fixed my program. I copy it hereby for the benefit of my fellow > noobs:
> fussal(X):- > X = 'c:/parse.pl', > see(X), > % This will give an error, because it expects a stream; > % seeing(X), > repeat, > get_char(T),print(T),T=end_of_file,!,seen.
> The conclusions: > 1, > If you omit the "seen" from the end of the end of the last line, the > next time you run the program you'll experience that the program only > reads "end_of_file" signs. This is because the "cursor position" of > file reading is assigned to the opened stream. (And a stream acts like > a global variable.)
> 2, > read/1 is for parsing prolog files. (It can handle the DCG syntax as > well.)
But you started with ISO style. The typical loop using read/2 is:
ISO says nothing on how files are specified, though most systems accept a (quoted) atom holding the filename. Generally they accept OS native syntax, which means in Windows you need 'C:\\Program Files\\...'. Often they also accept the POSIX / syntax as a portable syntax.
> On 2008-05-10, levili...@gmail.com <levili...@gmail.com> wrote:
> > I fixed my program. I copy it hereby for the benefit of my fellow > > noobs:
> > fussal(X):- > > X = 'c:/parse.pl', > > see(X), > > % This will give an error, because it expects a stream; > > % seeing(X), > > repeat, > > get_char(T),print(T),T=end_of_file,!,seen.
> > The conclusions: > > 1, > > If you omit the "seen" from the end of the end of the last line, the > > next time you run the program you'll experience that the program only > > reads "end_of_file" signs. This is because the "cursor position" of > > file reading is assigned to the opened stream. (And a stream acts like > > a global variable.)
> > 2, > > read/1 is for parsing prolog files. (It can handle the DCG syntax as > > well.)
> But you started with ISO style. The typical loop using read/2 is:
> ISO says nothing on how files are specified, though most systems accept > a (quoted) atom holding the filename. Generally they accept OS native > syntax, which means in Windows you need 'C:\\Program Files\\...'. Often > they also accept the POSIX / syntax as a portable syntax.