Unbound variables

Discussion of Common Lisp
Post Reply
jameschristian
Posts: 2
Joined: Tue Nov 26, 2013 12:42 am

Unbound variables

Post by jameschristian » Wed Nov 27, 2013 4:30 pm

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?

sylwester
Posts: 133
Joined: Mon Jul 11, 2011 2:53 pm

Re: Unbound variables

Post by sylwester » Thu Nov 28, 2013 4:13 pm

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
I'm the author of two useless languages that uses BF as target machine.
Currently I'm planning a Scheme compiler :p

Post Reply