Page 1 of 1

Unbound variables

Posted: Wed Nov 27, 2013 4:30 pm
by jameschristian
Hi all,

I am new to Lisp and am having a little trouble. I have written some really simple programs and am trying to get them to run with GCL, but keep getting an error saying that the variables are unbound. The programs look something like this:

Code: Select all

(defun test (X List) 
(member 'X 'List))
or this:

Code: Select all


 (defun doLoop
(do ((x 0 (+ x 2)) (y 0 (- y 2)))
((= x 2048) (print 'done))
(print x)
(print y))
)
Like I said, when I try to run these are anything like them, I am getting an error message saying that X is unbound. When I run the functions by themselves in GCL, they do just fine. Like if I went to the GCL terminal and typed:

Code: Select all

(member 'X '(A B X Y))
It would behave normally and return (X Y) as I would expect. What gives?

Re: Unbound variables

Posted: Thu Nov 28, 2013 4:13 pm
by sylwester
Hi there

I think I answered your first problem already so I'll jump to your doLoop function:
jameschristian wrote: or this:

Code: Select all

(defun doLoop
  (do ((x 0 (+ x 2)) (y 0 (- y 2)))
        ((= x 2048) (print 'done))
        (print x)
        (print y)))
Like I said, when I try to run these are anything like them, I am getting an error message saying that X is unbound. When I run the functions by themselves in GCL, they do just fine. Like if I went to the GCL terminal and typed:
That is not so strange since the body does work on it's own. Your error is that you didn't supply any arguments. For no argument function you supply the empty list. Here is how to fix it:;

Code: Select all

(defun doLoop () ; empty list for no arguments
  (do ((x 0 (+ x 2)) (y 0 (- y 2)))
        ((= x 2048) (print 'done))
        (print x)
        (print y)))
Br,
Syl