Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How should out of bounds values be handled?

0 views
Skip to first unread message

The Quiet Center

unread,
Feb 8, 2010, 9:59:07 PM2/8/10
to
In this simple program:

% https://prof.ti.bfh.ch/hew1/informatik3/prolog/p-99/p01.pl
% P01 (*): Find the last element of a list

% my_last(X,L) :- X is the last element of the list L
% (element,list) (?,?)

% Note: last(?Elem, ?List) is predefined

my_last(X,[X]).
my_last(X,[_|L]) :- my_last(X,L).

% ========================= end program

How should one specify that the behavior is undetermined for an empty
input list?

Chip Eastham

unread,
Feb 9, 2010, 12:21:07 AM2/9/10
to
On Feb 8, 9:59 pm, The Quiet Center <thequietcen...@gmail.com> wrote:
> In this simple program:
>
> %https://prof.ti.bfh.ch/hew1/informatik3/prolog/p-99/p01.pl

What happens is that the predicate, as written,
fails when the second argument is an empty list.
Whether you wish to modify the predicate to get
a different behavior depends on your intention.

regards, chip

0 new messages