(defun foo (&aux (defvar x 10))
(print x))
defines a local variable X, just like a LET would do. same function if written in a file and then compiled on sbcl as: sbcl --script file.lisp gives error:
; in: DEFUN FOO
; (DEFUN FOO (&AUX (DEFVAR X 10)) (PRINT X))
; --> PROGN SB-INT:NAMED-LAMBDA
; ==>
; #'(SB-INT:NAMED-LAMBDA FOO
; (&AUX (DEFVAR X 10))
; (BLOCK FOO (PRINT X)))
;
; caught ERROR:
; malformed &AUX binding specifier: (DEFVAR X 10)
;
; compilation unit finished
; caught 1 ERROR condition
unhandled SB-INT:COMPILED-PROGRAM-ERROR in thread #<SB-THREAD:THREAD
"main thread" RUNNING
{10029B8FC3}>:
Execution of a form compiled with errors.
Form:
#'(NAMED-LAMBDA FOO
(&AUX (DEFVAR X 10))
(BLOCK FOO (PRINT X)))
Compile-time error:
malformed &AUX binding specifier: (DEFVAR X 10)
0: (SB-DEBUG::MAP-BACKTRACE
#<CLOSURE (LAMBDA # :IN BACKTRACE) {1002A39DEB}>
:START
0
:COUNT
128)
1: (BACKTRACE 128 #<SB-SYS:FD-STREAM for "standard error" {10029BA863}>)
2: (SB-DEBUG::DEBUGGER-DISABLED-HOOK
#<SB-INT:COMPILED-PROGRAM-ERROR {1002A373D3}>
#<unavailable argument>)
3: (SB-DEBUG::RUN-HOOK
*INVOKE-DEBUGGER-HOOK*
#<SB-INT:COMPILED-PROGRAM-ERROR {1002A373D3}>)
4: (INVOKE-DEBUGGER #<SB-INT:COMPILED-PROGRAM-ERROR {1002A373D3}>)
5: (ERROR
SB-INT:COMPILED-PROGRAM-ERROR
:MESSAGE
"malformed &AUX binding specifier: (DEFVAR X 10)"
:SOURCE
"#'(NAMED-LAMBDA FOO
(&AUX (DEFVAR X 10))
(BLOCK FOO (PRINT X)))")
6: (#:EVAL-THUNK)
7: (SB-INT:SIMPLE-EVAL-IN-LEXENV
(SB-INT:NAMED-LAMBDA FOO
(&AUX (DEFVAR X 10))
(BLOCK FOO (PRINT X)))
#<NULL-LEXENV>)
8: (SB-INT:SIMPLE-EVAL-IN-LEXENV
(SB-IMPL::%DEFUN 'FOO
(SB-INT:NAMED-LAMBDA FOO
(&AUX (DEFVAR X 10))
(BLOCK FOO (PRINT X)))
NIL 'NIL (SB-C:SOURCE-LOCATION))
#<NULL-LEXENV>)
9: (SB-INT:SIMPLE-EVAL-IN-LEXENV
(EVAL-WHEN (:LOAD-TOPLEVEL :EXECUTE)
(SB-IMPL::%DEFUN 'FOO
(SB-INT:NAMED-LAMBDA FOO
(&AUX (DEFVAR X 10))
(BLOCK FOO (PRINT X)))
NIL 'NIL (SB-C:SOURCE-LOCATION)))
#<NULL-LEXENV>)
10: (SB-INT:SIMPLE-EVAL-IN-LEXENV
(DEFUN FOO (&AUX (DEFVAR X 10)) (PRINT X))
#<NULL-LEXENV>)
11: (EVAL-TLF (DEFUN FOO (&AUX (DEFVAR X 10)) (PRINT X)) 7 #<NULL-LEXENV>)
12: ((FLET SB-FASL::EVAL-FORM :IN SB-INT:LOAD-AS-SOURCE)
(DEFUN FOO (&AUX (DEFVAR X 10)) (PRINT X))
7)
13: (SB-INT:LOAD-AS-SOURCE
#<SB-SYS:FD-STREAM for "file /home/student/3357/fib.lisp" {10029C1513}>
:VERBOSE
NIL
:PRINT
NIL
:CONTEXT
"loading")
14: ((FLET SB-FASL::LOAD-STREAM :IN LOAD)
#<SB-SYS:FD-STREAM for "file /home/student/3357/fib.lisp" {10029C1513}>
NIL)
15: (LOAD
#<SB-SYS:FD-STREAM for "file /home/student/3357/fib.lisp" {10029C1513}>
:VERBOSE
NIL
:PRINT
NIL
:IF-DOES-NOT-EXIST
T
:EXTERNAL-FORMAT
:DEFAULT)
16: ((FLET SB-IMPL::LOAD-SCRIPT :IN SB-IMPL::PROCESS-SCRIPT)
#<SB-SYS:FD-STREAM for "file /home/student/3357/fib.lisp" {10029C1513}>)
17: ((FLET #:WITHOUT-INTERRUPTS-BODY-5599 :IN SB-IMPL::PROCESS-SCRIPT))
18: (SB-IMPL::PROCESS-SCRIPT "fib.lisp")
19: (SB-IMPL::TOPLEVEL-INIT)
20: ((FLET #:WITHOUT-INTERRUPTS-BODY-236911 :IN SAVE-LISP-AND-DIE))
21: ((LABELS SB-IMPL::RESTART-LISP :IN SAVE-LISP-AND-DIE))
unhandled condition in --disable-debugger mode, quitting
what is the problem with old version of assigning the variable &aux ?
If we look at the syntax of lambda lists , we see this:
lambda-list::= (var*
[&optional {var | (var [init-form [supplied-p-parameter]])}*]
[&rest var]
[&key {var | ({var | (keyword-name var)}
[init-form [supplied-p-parameter]])}*
[&allow-other-keys]]
[&aux {var | (var [init-form])}*])
Above is the syntax for argument list declarations for normal functions.
If you look at your form, you might want to find out what the symbol DEFVAR
is supposed to do and if it makes any sense in a lambda list...
Let's run try it in a REPL
* (defun foo (&aux (defvar x 10))
(print x))
; in: DEFUN FOO
; (SB-INT:NAMED-LAMBDA FOO
; (&AUX (DEFVAR X 10))
; (BLOCK FOO (PRINT X)))
;
; caught ERROR:
; malformed &AUX binding specifier: (DEFVAR X 10)
debugger invoked on a SB-INT:SIMPLE-PROGRAM-ERROR:
malformed &AUX binding specifier: (DEFVAR X 10)
SBCL clearly detects the syntax error.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.