[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 and enter the following line: 

even_number(N) :- 0 is N /\ 1.

Save the file and start the prolog interpreter in the directory containing

GNU Prolog 1.3.1
By Daniel Diaz
Copyright (C) 1999-2009 Daniel Diaz
| ?- [myeven].
compiling /tmp/ for byte code...
/tmp/ compiled, 2 lines read - 366 bytes written, 22 ms

| ?- 

At this point we have loaded the code in into the interpreter
and you can test it so:

| ?- even_number(22).


| ?- even_number(22).

| ?- even_number(-22).

| ?- even_number(3).  

| ?- even_number(-223).

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]