how can I implement this in macro?
From: lisplover (lisplover_at_hotmail.com)
Date: 03/29/05
- Next message: Thomas A. Russ: "Re: evaluating binded symbols"
- Previous message: david: "dll calls"
- Next in thread: Peter Scott: "Re: how can I implement this in macro?"
- Reply: Peter Scott: "Re: how can I implement this in macro?"
- Reply: josephoswaldgg_at_hotmail.com: "Re: how can I implement this in macro?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 28 Mar 2005 17:22:54 -0800
I am reading PG's on lisp and find this
(defvar *!equivs* (make-hash-table))
(defun ! (fn)
(or (gethash fn *!equivs*) fn))
(defun def! (fn fn!)
(setf (gethash fn *!equivs*) fn!))
to return a destructive equivalent. He comments that "Since the
relation between a function and its destructive counterpart will
usually be known before runtime, it would be most efficient to define !
as a macro, or even provide a read macro for it."
I try to implement that in macro. but find that when I define
(defmacro !(fn)
`(gethash (symbol-function ',fn) *!equivs*))
It is fine to call
CL-USER>(funcall (! reverse) '(1 2))
->(2 1)
But when I call it through a function
CL-USER> (defun test2(fn)
(funcall (! fn) '(1 2)))
TEST2
CL-USER> (test2 'reverse)
Error occurs.
SYMBOL-FUNCTION: undefined function FN
[Condition of type SYSTEM::SIMPLE-UNDEFINED-FUNCTION]
Would anyone like to point out what is the proper way to do it in
macro? Thanks.
- Next message: Thomas A. Russ: "Re: evaluating binded symbols"
- Previous message: david: "dll calls"
- Next in thread: Peter Scott: "Re: how can I implement this in macro?"
- Reply: Peter Scott: "Re: how can I implement this in macro?"
- Reply: josephoswaldgg_at_hotmail.com: "Re: how can I implement this in macro?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|