Please use code tags in the future. There is a Code button above the editing are which can be used to display preformatted text like ascii-trees and code. I have also moved the topic to Common Lisp subforum, since I am assuming Common Lisp from the presence of DEFUN. If it is a different dialect of Lisp please specify.

Your function is not properly recursive, as the non-recursive case is not a base case. In this case a base case is an empty list representing lack of leaf nodes. Consider the non-base, recursive, case first. You need to collect a node value, a number of leaves, and then append to that a representation of leaves. A non-existent leaf does not appear in this representation, which means that the base case can return NIL, which in Common Lisp is equivalent to an empty list, which will be ignored when appending.

To generate leaf representation you need to call the function recursively on the second and third element of the list, which can be accessed with SECOND and THIRD functions, or the old fashioned CADR and CADDR, and then append the results.

Last edited by Ramarren on Mon Dec 05, 2011 12:12 pm, edited 1 time in total.
Reason:explain the topic move

You have to think what is being passed to the function. It is either a NIL, representing an non-existent leaf, or a list of one, two or three elements. This are the only two possibilities, which means that the conditional only needs two branches, not three as in your attempt.

A convenient fact about CADR and CADDR in this case is that since both CAR and CDR are defined to return NIL when called on NIL, they will return NIL even if the list is too short, which means you don't have to check length of the list when making the recursive call.

CONS constructs a list only if the second argument is a list or NIL (which is an empty list in CL), and it adds the first argument as an element, whatever the first argument is. To merge two lists you should use APPEND. In your case you want to add both the node and the number of leaves to the front of leaf representation, which means you have to use CONS nested.

The return value of your function is a list. You have two recursive calls, which means two lists. As I said, you need APPEND to append those two lists together. And then use CONS twice nested to add the number of leaves and the node to the result of that.