CL-USER> (defparameter b 0)
A
CL-USER> (defun test (a)
(print (symbol-value a)))
TEST
CL-USER> (test 'a)
A
A
CL-USER> (test 'b)
0
0
I dont get second example, it should see dynamic binding ... afik

Thanks
makia wrote:I dont get second example, it should see dynamic binding ... afik
Ramarren wrote:makia wrote:I dont get second example, it should see dynamic binding ... afik
But you do see dynamic binding, so what is confusing? In the second example a is bound to symbol b, and the symbol-value returns, which is a function, returns the dynamic binding of b. In the first example a is bound to a, and then symbol-value returns the value of a, which is a.
But I don't think that making function arguments special is a good idea, and I can't really imagine any case where this would be more useful than confusing. There is a reason for *a* convention after all...
makia wrote:yes, nevermind the convention, this was just test of my understanding of language
btw. dynamic binding of a is 0, not symbol a
(test 'a)
(test 'b)
makia wrote:ahh, i expiremented a little .... and got it ...
defparameter establish dynamic variable so "a" in (defun test (a) ...) is dynamic not lexical (that's is what confused me, i thought "a" is lexical inside the function)
Ramarren wrote:makia wrote:ahh, i expiremented a little .... and got it ...
defparameter establish dynamic variable so "a" in (defun test (a) ...) is dynamic not lexical (that's is what confused me, i thought "a" is lexical inside the function)
As far as I know, there is no way to un-special (ie. turn dynamic variable into lexical one) a symbol, locally or otherwise. This is I believe considered a flaw in the language, but it doesn't really come up that often.
Users browsing this forum: No registered users and 9 guests