[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Just for Fun ...
- To: BUG-LISP at MIT-MC
- Subject: Just for Fun ...
- From: Kent M. Pitman <KMP at MIT-MC>
- Date: Tue, 11 Nov 80 23:27:00 GMT
- Cc: JAR at MIT-MC, RICH at MIT-AI, DANIEL at MIT-AI
- Original-date: 11 November 1980 18:27-EST
Here's a couple of cute Maclisp toys to play with ...
[1] Fun with Shadowing.
(DEFMACRO FOO (X) `(CAR ,X))
(MAPCAR #'FOO '((A B) (C D) (E F)))
Do you know why it loses?
(DEFUN FOO (X) (FOO X))
(DEFMACRO FOO (X) `(CAR ,X))
(MAPCAR #'FOO (X) '((A B) (C D) (E F)))
Do you know why it wins?
[2] Fun with Interpreted Macros.
(DEFMACRO MMAPCAR (FN L)
(LET ((VAR (GENSYM))
(CALL (IF (AND (LISTP FN) (MEMQ (CAR FN) '(QUOTE FUNCTION)))
`(,(CADR FN))
`(FUNCALL ,FN))))
`((LAMBDA (,VAR)
(COND (,VAR (CONS (,@CALL (CAR ,VAR)) (MMAPCAR ,FN (CDR ,VAR))))))
,L)))
(SETQ GRIND-MACROEXPANDED T)
(DEFMACRO F (X) `(CAR ,X))
(MMAPCAR #'F '((A B) (C D) (E F)))
(SPRINTER +)
(DEFUN G (X) (MMAPCAR #'F X))
(G '((A B) (C D)))
(GRINDEF G)
(G '((A B)))
(GRINDEF G)
(G '((A B) (C D) (E F)))
[3] Fun with Compiled Macros. (Extra Credit)
Why doesn't the definition of G from [2] compile?