How should out of bounds values be handled?
Bei der Gruppe, für die Sie eine Mitteilung verfassen, handelt es sich um eine
Usenet-Gruppe . Wenn Sie in dieser Gruppe Nachrichten posten, ist Ihre E-Mail-Adresse für jeden im Internet sichtbar
Ihre Antwort wurde nicht gesendet.
Die Nachricht wurde übermittelt.
Newsgroups: comp.lang.prolog
Von:
The Quiet Center <thequietcen... @gmail.com>
Datum: Mon, 8 Feb 2010 18:59:07 -0800 (PST)
Lokal: Di 9 Feb. 2010 03:59
Betreff: How should out of bounds values be handled?
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?
Sie müssen sich
anmelden , bevor Sie Nachrichten veröffentlichen können.
Sie haben nicht die erforderliche Berechtigung zum Posten.
Newsgroups: comp.lang.prolog
Von:
Chip Eastham <hardm... @gmail.com>
Datum: Mon, 8 Feb 2010 21:21:07 -0800 (PST)
Lokal: Di 9 Feb. 2010 06:21
Betreff: Re: How should out of bounds values be handled?
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 > % 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?
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
Sie müssen sich
anmelden , bevor Sie Nachrichten veröffentlichen können.
Sie haben nicht die erforderliche Berechtigung zum Posten.