Hello.
I'm facing a strange scope problem: simply put...
(defun bar(expr x v)
(setf result expr)
(setf x v)
(eval result)
)
> (bar '(* x 2) 'x 10)
Error in KERNEL::UNBOUND-SYMBOL-ERROR-HANDLER: the variable X is unbound.
[Condition of type UNBOUND-VARIABLE]
-------------------------------------------------------------------------------------------------
but when i type the same commands on system the result comes...but actually i want to implement this in a function for my code
scope problem
-
- Posts: 406
- Joined: Sat Mar 07, 2009 6:17 pm
- Location: Brazil
- Contact:
Re: scope problem
You are obviously trying to do something the wrong way, you shouldn't need to use EVAL and neither to assign symbol's values (like you are trying to do with X). Besides, you didn't define the variable RESULT, that way the code won't do what you expect it to.
By doing
You are not changing the global value of X, but just the value of X as a local variable inside the function BAR. EVAL evaluates its expression in a clean environment, that it, without ANY local variables, including the variable X of BAR.
In any case, you have to change the approach of solving your problem, whatever that is. I suggest that you get some book about Common Lisp and learn it before anything else, I recommend the book Practical Common Lisp.
By doing
Code: Select all
(setf x v)
In any case, you have to change the approach of solving your problem, whatever that is. I suggest that you get some book about Common Lisp and learn it before anything else, I recommend the book Practical Common Lisp.
Re: scope problem
yep...
i got the result
i defined the variables on the top
by using defparameter
(defparameter x 1)
etc...
then i got the result.
btw thanks for the book.
i got the result
i defined the variables on the top
by using defparameter
(defparameter x 1)
etc...
then i got the result.
btw thanks for the book.