Created
January 31, 2018 20:16
-
-
Save jmercouris/480ef407b60df935b6b3bf822dbe9262 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Macro | |
(defmacro deferredvar (variable value &optional (documentation nil)) | |
`(progn | |
(defvar ,variable nil ,documentation) | |
(push (lambda () | |
(setf ,variable | |
(if (and (symbolp (first ,value)) | |
(fboundp (first ,value))) | |
(funcall (first ,value) (rest ,value)) | |
,value))) | |
*deferred-variables*))) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Macro Usage | |
(deferredvar fishes-count '(count-fishes :type "salmon") "this function counts the fishes") | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Macro Expansion | |
(PROGN | |
(DEFVAR FISHES-COUNT NIL "this function counts the fishes") | |
(PUSH (LAMBDA NIL (SETF FISHES-COUNT | |
(IF (AND (SYMBOLP (FIRST '(COUNT-FISHES "salmon"))) | |
(FBOUNDP (FIRST '(COUNT-FISHES "salmon")))) | |
(FUNCALL (FIRST '(COUNT-FISHES "salmon")) | |
(REST '(COUNT-FISHES "salmon"))) | |
'(COUNT-FISHES :TYPE "salmon")))) | |
*DEFERRED-VARIABLES*)) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Function definition | |
(defun count-fishes (type-of-fish) | |
...) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Problem | |
The value ("salmon") is not of the expected type (OR | |
PATHNAME | |
STREAM | |
STRING). | |
[Condition of type TYPE-ERROR] | |
Restarts: | |
0: [RETRY] Retry SLIME REPL evaluation request. | |
1: [*ABORT] Return to SLIME's top level. | |
2: [ABORT-BREAK] Reset this thread | |
3: [ABORT] Kill this thread | |
Backtrace: | |
0: (count-fishes ("salmon")) | |
1: (#<Anonymous Function #x3020018838CF>) | |
2: (INITIALIZE-DEFERRED-VARIABLES) | |
3: (CCL::CALL-CHECK-REGS INITIALIZE-DEFERRED-VARIABLES) | |
4: (CCL::CHEAP-EVAL (INITIALIZE-DEFERRED-VARIABLES)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment