May 3, 2010 #1 snaps11 Programmer Joined May 3, 2010 Messages 1 Location US Prolog quick question Explain what the following Prolog code does. Assume the third parameter is the result. a( 1, [Hd | _Tl], Hd ). a( N, [_ | Tl], Elem ) :- N > 1, N1 is N - 1, a( N1, Tl, Elem).
Prolog quick question Explain what the following Prolog code does. Assume the third parameter is the result. a( 1, [Hd | _Tl], Hd ). a( N, [_ | Tl], Elem ) :- N > 1, N1 is N - 1, a( N1, Tl, Elem).
May 4, 2010 #2 joel76 Programmer Joined Aug 31, 2008 Messages 295 Location FR Did you test it on a list ? Upvote 0 Downvote
Jul 15, 2010 #3 kamileo Programmer Joined Jul 15, 2010 Messages 6 Location PL It returns the N-element of the list. Upvote 0 Downvote