I created a (simple) function called make-alias which creates a function
with the same semantics as another function. It which works like this:
(defun foo ....)
-> foo
(foo 5)
-> 13.27
(make-alias foo2 foo)
-> foo2
(foo2 5)
-> 13.27
Now, I want to make another version that works for macros that will work
very similar:
(macro-alias dt do-times)
-> dt
(dt (i 3) (princ i))
-> 012
How can I do this?
Lowell
"Lowell" <······@cs.ubc.ca> wrote in message ·················@mughi.cs.ubc.ca...
> I created a (simple) function called make-alias which creates a function
> with the same semantics as another function. It which works like this:
>
> How can I do this?
(defmacro macro-alias (alias macro)
(let ((body (gensym)))
`(defmacro ,alias (&body ,body)
`(,',macro ,@,body))))
CL-USER 36 > (macro-alias dt dotimes)
DT
CL-USER 37 > (dt (i 3) (princ i))
012
NIL
CL-USER 38 >
Wade
perfect! thanks
Wade Humeniuk wrote:
> "Lowell" <······@cs.ubc.ca> wrote in message ·················@mughi.cs.ubc.ca...
>
>>I created a (simple) function called make-alias which creates a function
>>with the same semantics as another function. It which works like this:
>>
>>How can I do this?
>
>
> (defmacro macro-alias (alias macro)
> (let ((body (gensym)))
> `(defmacro ,alias (&body ,body)
> `(,',macro ,@,body))))
>
> CL-USER 36 > (macro-alias dt dotimes)
> DT
>
> CL-USER 37 > (dt (i 3) (princ i))
> 012
> NIL
>
> CL-USER 38 >
>
> Wade
Wade Humeniuk <····@nospam.nowhere> wrote:
+---------------
| "Lowell" <······@cs.ubc.ca> wrote:
| > I created a (simple) function called make-alias which creates a function
| > with the same semantics as another function. It which works like this:
| > How can I do this?
|
| (defmacro macro-alias (alias macro)
| (let ((body (gensym)))
| `(defmacro ,alias (&body ,body)
| `(,',macro ,@,body))))
+---------------
Is the GENSYM really necessary in this case, given that the *only* thing
the aliased macro does is expand into a single call of the original?
Wouldn't this be good enough?
(defmacro macro-alias (alias macro)
`(defmacro ,alias (&body body)
`(,',macro ,@body)))
I understand how in general you want to be careful about variable capture,
but in this case won't the variable BODY have disappeared before the aliased
macro ever expands? And thus there won't be any BODY to capture?
What am I missing?
-Rob
-----
Rob Warnock, PP-ASEL-IA <····@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607
"Rob Warnock" <····@rpw3.org> wrote in message ···························@speakeasy.net...
>
> Is the GENSYM really necessary in this case, given that the *only* thing
> the aliased macro does is expand into a single call of the original?
> Wouldn't this be good enough?
>
> (defmacro macro-alias (alias macro)
> `(defmacro ,alias (&body body)
> `(,',macro ,@body)))
>
I am not sure, I just do automatically and I will never have to
worry about it again. You are probably right.
Wade
"Wade Humeniuk" <····@nospam.nowhere> writes:
> "Rob Warnock" <····@rpw3.org> wrote in message ···························@speakeasy.net...
> >
> > Is the GENSYM really necessary in this case, given that the *only* thing
> > the aliased macro does is expand into a single call of the original?
> > Wouldn't this be good enough?
> >
> > (defmacro macro-alias (alias macro)
> > `(defmacro ,alias (&body body)
> > `(,',macro ,@body)))
> >
>
> I am not sure, I just do automatically and I will never have to
> worry about it again. You are probably right.
That's right. A gensym is not needed here. There are no
user-variables competing in the same lexical contour, so there
is no conflict issue. Following on a tradition I got from Symbolics,
I often name such variables .body. in order to identify them as
conceptual gensyms, that is program-introduced variables, but ones
that are known to be safe and to require no gensyming.
Then again, you do have to be careful about using .xxx.
names immediately after a comma in a backquote expression...
On Sat, 16 Aug 2003 19:11:35 -0700, Lowell <······@cs.ubc.ca> wrote:
>I created a (simple) function called make-alias which creates a function
>with the same semantics as another function. It which works like this:
>
>(defun foo ....)
>-> foo
>
>(foo 5)
>-> 13.27
>
>(make-alias foo2 foo)
>-> foo2
>
>(foo2 5)
>-> 13.27
>
>Now, I want to make another version that works for macros that will work
>very similar:
>
>(macro-alias dt do-times)
>-> dt
>
>(dt (i 3) (princ i))
>-> 012
>
>How can I do this?
>
(defmacro alias-macro (alias macro)
`(defmacro ,alias (&whole form &rest ignore)
(declare (ignore ignore))
(cons ',macro (cdr form))))
JP Massar wrote:
> On Sat, 16 Aug 2003 19:11:35 -0700, Lowell <······@cs.ubc.ca> wrote:
>
>
>>I created a (simple) function called make-alias which creates a function
>>with the same semantics as another function. It which works like this:
>>
>>(defun foo ....)
>>-> foo
>>
>>(foo 5)
>>-> 13.27
>>
>>(make-alias foo2 foo)
>>-> foo2
>>
>>(foo2 5)
>>-> 13.27
>>
>>Now, I want to make another version that works for macros that will work
>>very similar:
>>
>>(macro-alias dt do-times)
>>-> dt
>>
>>(dt (i 3) (princ i))
>>-> 012
>>
>>How can I do this?
>>
>
>
>
>
> (defmacro alias-macro (alias macro)
> `(defmacro ,alias (&whole form &rest ignore)
> (declare (ignore ignore))
> (cons ',macro (cdr form))))
You can also do:
(setf (symbol-function 'foo2) (symbol-function 'foo)).
Paul
"Paul F. Dietz" <·····@dls.net> wrote in message ···························@dls.net...
> You can also do:
>
> (setf (symbol-function 'foo2) (symbol-function 'foo)).
I think you mean
CL-USER 4 > (setf (macro-function 'dt) (macro-function 'dotimes))
#<function DOTIMES 2020AFF2>
CL-USER 5 > (dt (i 3) 2)
NIL
CL-USER 6 > (dt (i 3) (princ i))
012
NIL
CL-USER 7 >
In LW
I get an error with symbol-function, dt does not act like a macro.
CL-USER 1 > (setf (symbol-function 'dt) (symbol-function 'dotimes))
#<function DOTIMES 2020AFF2>
CL-USER 2 > (dt (i 3) 2)
Error: Undefined function I called with arguments (3).
1 (continue) Try invoking I again.
2 Return some values from the call to I.
3 Try invoking something other than I with the same arguments.
4 Set the symbol-function of I to another function.
5 (abort) Return to level 0.
6 Return to top loop level 0.
Wade