在 Clojure 中,我可以定义一系列函数,然后像调用其他值一样调用它们,如下所示:
(doseq [op [+ - * /]]
(println (op 1 2 3 4)))
产生以下输出:
10
-8
24
1/24
nil
尝试在 Common Lisp 中做同样的事情只会导致错误:
(dolist (op '(+ - * /))
(print (op 1 2 3 4))
; in: DOLIST (OP '(+ - * /))
; (LET ((OP (TRULY-THE (MEMBER / * - +) (CAR #:N-LIST671))))
; (SETQ #:N-LIST671 (CDR #:N-LIST671))
; (TAGBODY (PRINT (OP 1 2 3 4))))
;
; caught STYLE-WARNING:
; The variable OP is defined but never used.
; in: DOLIST (OP '(+ - * /))
; (OP 1 2 3 4)
;
; caught STYLE-WARNING:
; undefined function: OP
;
; compilation unit finished
; Undefined function:
; OP
; caught 2 STYLE-WARNING conditions
debugger invoked on a UNDEFINED-FUNCTION:
The function COMMON-LISP-USER::OP is undefined.
Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Exit debugger, returning to top level.
("undefined function")
打电话给我op
也#'op
不起作用。
那么有没有办法在 CL 中做到这一点?