FB18 - Das Forum für Informatik

fb18.de / Diplom Informatik / Unterbereich Grundstudium / Praktische Informatik

P1: mylength / append

P1: mylength / append 2005-02-07 01:55
Anonymer User
Hi!
Hab zwei Fragen:
Einmal, kann mir jemand anhand eines traces zeigen wie genau das N is N1+1 im Prädikat mylength/2 funktioniert?

mylength([ ],0).
mylength([_|Rest],N) :-
mylength(Rest,N1),
N is N1+1

Und zum zweiten, anhand ein traces wie das genau funktioniert mit dem Kopf abziehen beim Prädikat append/3:

app([ ],L,L).
app([Kopf|Rest1],L2,[Kopf|ZR]) :-
app(Rest1,L2,ZR)

Danke!

(edit: Topictitel – fal)

Re: P1: mylength / append 2005-02-07 02:00
Anarch
Probier mal

?- guitracer. % The graphical front-end will be used for subsequent tracing Yes ?- trace, mylength([a,b,c,d,e,f,g], Length).
Vielleicht hilft das beim verstehen :-)