I'm a new comer to Prolog, and I don't understand how to do this in my exercise:
If I use the following command in the SWI-prolog, it will show the special vars like _G373.
14 ?- write([[_,_,_,_],[_,_,_,#],[_,_,_,_]]).
[[_G403,_G406,_G409,_G412],[_G418,_G421,_G424,#],[_G433,_G436,_G439,_G442]]
true.
But in .pl files, if I read the same list of list from a file and store them in Puzzle,
read_file(Filename, Content) :- %read file using read lines
open(Filename, read, Stream), %open a file, start read stream
read_lines(Stream, Content), %using readlines store content from stream into content
close(Stream). %Close the stream
read_lines(Stream, Content) :- %read lines from read a single line
read_line(Stream, Line, Last), %using read_line
( Last = true %if last = ture, means read to the file end, make line = [], content = []
-> ( Line = [] %else make content = [line]
-> Content = []
; Content = [Line]
)
; Content = [Line|Content1], %store the lines from up to bottom
read_lines(Stream, Content1)
).
read_line(Stream, Line, Last) :- %read line from read a character
get_char(Stream, Char), %
( Char = end_of_file %if read to the file end, make line = [], last = true
-> Line = [], %else if read to the line's end, make line[], last = false
Last = true
; Char = '\n'
-> Line = [],
Last = false
; Line = [Char|Line1],
read_line(Stream, Line1, Last)
). %else store the character in order, just for one line
when I use
write('Puzzle'),nl,write(Puzzle),nl.
, it only shows
Puzzle
[[_,_,_,_],[_,_,_,#],[_,_,_,_]]
How can I change these _ into special vars like the SWI-Prolog?
Thanks.