[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Users-prolog Digest, Vol 79, Issue 2
From: |
Duncan Patton a Campbell |
Subject: |
Re: Users-prolog Digest, Vol 79, Issue 2 |
Date: |
Fri, 18 Dec 2009 11:36:08 -0700 |
On Fri, 18 Dec 2009 12:00:25 -0500
address@hidden wrote:
>
> James Gale wrote:
...
I assuming you want a function that tests whether a number is even or odd?
Such a function is not built into Gprolog, so you will need to construct
one. exempli gratia:
With a text editor (vi on *nix, notepad on Wondiws) load edit a file, called
myeven.pl and enter the following line:
even_number(N) :- 0 is N /\ 1.
Save the file and start the prolog interpreter in the directory containing
myeven.pl
gprolog
GNU Prolog 1.3.1
By Daniel Diaz
Copyright (C) 1999-2009 Daniel Diaz
| ?- [myeven].
compiling /tmp/myeven.pl for byte code...
/tmp/myeven.pl compiled, 2 lines read - 366 bytes written, 22 ms
yes
| ?-
At this point we have loaded the code in myeven.pl into the interpreter
and you can test it so:
| ?- even_number(22).
yes
| ?- even_number(22).
yes
| ?- even_number(-22).
yes
| ?- even_number(3).
no
| ?- even_number(-223).
no
| ?- even_number(-223.0).
uncaught exception: error(type_error(integer,-223.0),(is)/2)
| ?-
This last error is because our one line function is factored
to only deal with integers.
I hope this helps.
Dhu
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Users-prolog Digest, Vol 79, Issue 2,
Duncan Patton a Campbell <=