Re: Four Easy Question

From: Benjamin Johnston (superhero_at_benjaminjohnston.com.au)
Date: 03/23/04


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
>
>
>



Relevant Pages

  • Re: Exception Thrown When Rotating Photos Successively
    ... As bob suggests it sounds like the old file-locking problem, ... Is there another type of stream you are thinking of that I'm not using ... |> Find great Windows Forms articles in Windows Forms Tips and Tricks ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Re:OT NV Senator plays hard ball?
    ... > BOB, ... What stream would that be? ... Once you get past that unfortunate rich Texan doctor stuff, ...
    (alt.vacation.las-vegas)
  • Re: Re:OT NV Senator plays hard ball?
    ... Tom ... BOB wrote: ... What stream would that be? ... > Once you get past that unfortunate rich Texan doctor stuff, ...
    (alt.vacation.las-vegas)
  • Re: Re:OT NV Senator plays hard ball?
    ... >> What is the far left fringe? ... DocTom seems pretty main stream. ... >> BOB ...
    (alt.vacation.las-vegas)
  • Is this a hoax or real?
    ... Coan's free Hidden File Detector software. ... Alice is the bad guy. ... location of a file that Bob, the good guy, can get to. ... Alice has her own Web server. ...
    (microsoft.public.security)