3
在Clojure中,我可以定義一個函數序列,然後調用他們就像他們自己被任何其他值,像這樣:調用的函數Common Lisp的列表
(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中做到這一點?
看看[common lisp如何讓我的變量作爲它在第一個列表中的操作符時運行?](http://stackoverflow.com/q/25221343/1281433) – 2014-10-03 20:24:38