Please see the following codes: (runs in clisp-2.34
-
[1]> (defun test (cdr '(x y z))
(list cdr x y z))
TEST
[2]>
-
You can see that the codes were accepted by the interpreter.
now if I call (test 1 '(2 3 4)) what will happen ?
Will the interpreter reply (1 2 3 4) ?
The answer is as the following :
-
Break 1 [3]> (test 1 '(2 3 4))
*** - EVAL: variable X has no value
The following restarts are available:
USE-VALUE :R1 You may input a value to be used instead of X.
STORE-VALUE :R2 You may input a new value for X.
ABORT :R3 ABORT
ABORT :R4 ABORT
Break 2 [4]>
-
It seens that destructuring not happen for the parameter list.
Thus the second argument '(2 3 4) must be asigned to the second
parameter '(x y z). If this is true , what will happened in my codes ?
(as the following)
(defun test (cdr '(x y z))
(list cdr '(x y z)))
If I try (test 1 '(2 3 4)) , will the interpreter return
(1 '(2 3 4)) ? The answer is as below :
-
Break 2 [4]> (defun test (cdr '(x y z))
(list cdr '(x y z)))
TEST
Break 2 [4]> (test 1 '(2 3 4))
(1 (X Y Z))
Break 2 [4]>
-
As you can see , the second argument just doesn't appear .
Where does it go ? Anything can help it come back ?
Many thanks!
··········@bbs.ee.ncu.edu.tw wrote:
> Please see the following codes: (runs in clisp-2.34
> -
> [1]> (defun test (cdr '(x y z))
> (list cdr x y z))
> TEST
> [2]>
> -
> You can see that the codes were accepted by the interpreter.
> now if I call (test 1 '(2 3 4)) what will happen ?
Chaos will ensue.
> Will the interpreter reply (1 2 3 4) ?
No. You will get n error of some kind.
> The answer is as the following :
> -
> Break 1 [3]> (test 1 '(2 3 4))
>
> *** - EVAL: variable X has no value
> The following restarts are available:
> USE-VALUE :R1 You may input a value to be used instead of X.
> STORE-VALUE :R2 You may input a new value for X.
> ABORT :R3 ABORT
> ABORT :R4 ABORT
> Break 2 [4]>
It is an error, but obviously not very informative. LWM is more
helpful, the answer is
Error: Non-symbol (QUOTE (X Y Z)) used as variable name in function TEST.
I'd wager that this error checking should be done at function definition
time, but that's the way CLisp and LWM behave.
> -
> It seens that destructuring not happen for the parameter list.
> Thus the second argument '(2 3 4) must be asigned to the second
> parameter '(x y z). If this is true , what will happened in my codes ?
Your code is simply incorrect. The syntax of argument lists is well
defined and - above all - unevaluated. The fact that CLisp is not doing
TRT is an unfortunate circumstance.
Cheers
--
Marco