[vox-tech] entering a prolog program?

Brian Lavender brian at brie.com
Sun Nov 21 23:49:22 PST 2010


On Sat, Nov 20, 2010 at 07:32:55PM -0600, Chanoch (Ken) Bloom wrote:
> On Fri, 2010-11-19 at 20:05 -0800, Brian Lavender wrote:
> > Can you type in axioms into prolog from the command line? All I seem to
> > be able to do is load a program and query it. 
> > 
> > Can I just enter the following program at the prolog prompt?
> > 
> > factorial(0,1).
> >   
> > factorial(A,B) :-  
> >            A > 0, 
> >            C is A-1,
> >            factorial(C,D),
> >            B is A*D. 
> > 
> > 
> > All I seem to be able to do is load it. I am using SWI prolog.
> > 
> > $ swipl
> > ?- ['factorial.pl'].
> > true.
> > 
> > If I try the following, I get an error. 
> > 
> > ?- factorial(0, 1).
> > ERROR: toplevel: Undefined procedure: factorial/2 (DWIM could not correct goal)
> 
> Typing [user]. the way you typed ['factorial.pl']. will enter an
> interactive rule entry mode. When you're finished with that mode, hit
> Ctrl-D to return to query mode.

Thanks. For the life of me I could not find that in the documentation.

brian
-- 
Brian Lavender
http://www.brie.com/brian/

"Program testing can be used to show the presence of bugs, but never to
show their absence!"

Professor Edsger Dijkstra
1972 Turing award recipient


More information about the vox-tech mailing list