[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Pass by reference in LISP

 Thanks, I finally go things to work, although I'm still not sure exactly why!?!
I used your example and restructured the problem.  This is a simplified test that
I did to get the method down correctly, and it worked fine.

? (defun test2 (n alist)
    "Recursively calls itself exanding it's list"
      ;(declare (notinline test2))
    (if (eql n 0)
      (setf alist (test2 (- n 1) alist)))
    (if (oddp n) 
      (cons n alist)
? (setf x nil)
? (setf x (test2 100 x))

I think I'm having the same kind of conceptual problem that I had when I went to 
C++'s concept of passing by reference

short& somefunc(short& x) {
  x = x * x;
  return x;}

versus the more fundamental passing a pointer (which is in effect what you are

cons must be returning a pointer to a list, the problem that I'm having is that
I'm afraid that a new list is being made up each time I call my "test2" function
recursively.  I wish there was some low level way I could follow along with LISP
so I can learn what it is actually doing as I call certain functions.  In my
real problem the recursion could get VERY deep (and the list VERY long).