After reading the descriptions of the invinsible "SYMBOL-VALUE" by Alan
Crowe ,
I did some trial of that function in ARC XLISP-stat , as the
followings:
> (defun test1 ()
(let ((s 3))
(symbol-value 's)))
TEST1
> (test1)
Error: The variable S is unbound.
Happened in: #<FSubr-LET: #dd3384>
>
You can see that ARC xlisp says that S is unbound , but in fact I have
done the local binding
by (let ((s 3)) in the function test1.
Further more , please see the followings:
> (defvar s "outside function")
S
> s
"outside function"
> (test1)
3
>
It seems that whether s is bound by LET decised on wheter global s is
definded.
Strange ? Some body helps me , please.
Thanks!!
(the version of my ARC xlisp can be checked in the following copyright
statements:
XLISP-PLUS version 3.04
Portions Copyright (c) 1988, by David Betz.
Modified by Thomas Almy and others.
XLISP-STAT Release 3.52.17 (Beta).
Copyright (c) 1989-1999, by Luke Tierney.)
··········@bbs.ee.ncu.edu.tw writes:
> After reading the descriptions of the invinsible "SYMBOL-VALUE" by Alan
> Crowe ,
> I did some trial of that function in ARC XLISP-stat , as the
> followings:
>
>> (defun test1 ()
> (let ((s 3))
> (symbol-value 's)))
> TEST1
>> (test1)
> Error: The variable S is unbound.
> Happened in: #<FSubr-LET: #dd3384>
>>
>
> You can see that ARC xlisp says that S is unbound , but in fact I have
> done the local binding
> by (let ((s 3)) in the function test1.
>
> Further more , please see the followings:
>
>> (defvar s "outside function")
> S
>> s
> "outside function"
>> (test1)
> 3
>>
>
> It seems that whether s is bound by LET decised on wheter global s is
> definded.
> Strange ? Some body helps me , please.
In Common Lisp, it's normal.
[15]> (disassemble (compile (defun test1 ()
(let ((s 3))
(symbol-value 's)))))
WARNING in TEST1 :
variable S is not used.
Misspelled or missing IGNORE declaration?
Disassembly of function TEST1
(CONST 0) = S
0 required arguments
0 optional arguments
No rest parameter
No keyword parameters
3 byte-code instructions:
0 (CONST&PUSH 0) ; S
1 (CALLS1 78) ; SYMBOL-VALUE
3 (SKIP&RET 1)
NIL
[16]>
Note how in the generated code you don't see anything about the (s 3).
Let's try something else:
[17]> (disassemble (compile (defun test1 ()
(let ((s 3))
(print s)
(print (symbol-value 'e))))))
Disassembly of function TEST1
(CONST 0) = 3
(CONST 1) = E
0 required arguments
0 optional arguments
No rest parameter
No keyword parameters
8 byte-code instructions:
0 (CONST&PUSH 0) ; 3
1 (PUSH-UNBOUND 1)
3 (CALLS1 132) ; PRINT
5 (CONST&PUSH 1) ; E
6 (CALLS1&PUSH 78) ; SYMBOL-VALUE
8 (PUSH-UNBOUND 1)
10 (CALLS1 132) ; PRINT
12 (SKIP&RET 1)
NIL
Now, look carefully. The code is printing the value of the binding
named S. and fetches the symbol-value of the symbol named E. As you
can see, in the compiled code, there absolutely no mention of S.
That's the point of lexical bindings: to be able to get rid of the
symbols naming them, and access directly the memory cells where the
values are stored.
Now, for special variables, you need to allocate a symbol record and
set or get its value slot. This is completely different.
[19]> (disassemble (compile (defun test1 ()
(let ((s 3))
(declare (special s))
(print s)
(print (symbol-value 's))))))
Disassembly of function TEST1
(CONST 0) = 3
(CONST 1) = S
0 required arguments
0 optional arguments
No rest parameter
No keyword parameters
reads special variable: S
11 byte-code instructions:
0 (CONST 0) ; 3
1 (BIND 1) ; S <<---- changes the symbol-value
3 (GETVALUE&PUSH 1) ; S
5 (PUSH-UNBOUND 1)
7 (CALLS1 132) ; PRINT
9 (CONST&PUSH 1) ; S
10 (CALLS1&PUSH 78) ; SYMBOL-VALUE
12 (PUSH-UNBOUND 1)
14 (CALLS1 132) ; PRINT
16 (UNBIND1) ; <<---- restores the old symbol-value
17 (SKIP&RET 1)
NIL
[20]> (test1)
3
3
3
--
"Remember, Information is not knowledge; Knowledge is not Wisdom;
Wisdom is not truth; Truth is not beauty; Beauty is not love;
Love is not music; Music is the best." -- Frank Zappa