Re: Four Easy Question
From: Benjamin Johnston (superhero_at_benjaminjohnston.com.au)
Date: 03/23/04
- Next message: Remko Troncon: "Re: Can all clauses be represented as Horn Clauses?"
- Previous message: Remko Troncon: "Re: Postdoc position in program development, analysis and transformation"
- In reply to: Benjamin Johnston: "Re: Four Easy Question"
- Next in thread: Martin Sondergaard: "Re: Four Easy Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 23 Mar 2004 23:12:12 +1000
You asked for some examples...
>
> "Linux Man" <steven_82m@hotmail.com> wrote in message
> news:150a16c6.0403211042.1b3c0612@posting.google.com...
> > Hi again
> >
> > I'm using SWI-Prolog
>
> > 1- How can I create a file in prolog?
>
> At the SWI-Prolog console type:
> help(open).
>
> > 2- How can I read from a file or check that, say
> > "john is father of bob" (father(john, bob)), from
> > that file?
>
> At the SWI-Prolog console type:
> help(consult).
> or
> help(read).
> or
> help(read_file_to_codes).
> or
> help(read_file_to_terms).
> or
> help(read_line_to_codes).
e.g.,
consult('filename.ext'),father(john, bob).
or
read_file_to_terms('filename.ext', Terms, []), member(father(john, bob),
Terms).
(though, this doesn't do inference -- it just checks whether you've
explicitly stated father(john, bob) in the file).
or
open('filename.ext', read, Stream),
repeat,
read(Stream, Term),
(Term = end_of_file ->
close(Stream)
;
Term = father(john,bob),
write('match found!'),
fail
).
> For other ways of reading, type:
> apropos(read).
>
> > 3- How can I write a new predicate in the created
> > file (e.g. father(jim, alice).)?
>
> At the SWI-Prolog console type:
> help(write).
>
> (use write/2, i.e., write(Term, Stream)).
open('filename.ext', write, Stream),
write(Stream, father(jim, alice)),
close(Stream).
>
> Does that answer your question?
>
> -Benjamin Johnston
>
>
>
- Next message: Remko Troncon: "Re: Can all clauses be represented as Horn Clauses?"
- Previous message: Remko Troncon: "Re: Postdoc position in program development, analysis and transformation"
- In reply to: Benjamin Johnston: "Re: Four Easy Question"
- Next in thread: Martin Sondergaard: "Re: Four Easy Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|