From: Lowell
Subject: how can I do this with macros?
Date: 
Message-ID: <bhmo8m$lti$1@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:

(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

From: Wade Humeniuk
Subject: Re: how can I do this with macros?
Date: 
Message-ID: <6kC%a.75294$tQ2.1919293@news1.telusplanet.net>
"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
From: Lowell
Subject: Re: how can I do this with macros?
Date: 
Message-ID: <bhmrqk$mo3$1@mughi.cs.ubc.ca>
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
From: Rob Warnock
Subject: Re: how can I do this with macros?
Date: 
Message-ID: <KeCcnYhGprK7Y92iXTWc-w@speakeasy.net>
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
From: Wade Humeniuk
Subject: Re: how can I do this with macros?
Date: 
Message-ID: <4Bh0b.24459$L6.273500@news2.telusplanet.net>
"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
From: Kent M Pitman
Subject: Re: how can I do this with macros?
Date: 
Message-ID: <sfwn0e6w1hc.fsf@shell01.TheWorld.com>
"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...
From: Conrad Barski
Subject: Re: how can I do this with macros?
Date: 
Message-ID: <a4af10cf.0308171050.142dba6@posting.google.com>
Also, look at the "abbrev" macros p 214:

http://www.paulgraham.com/onlisptext.html
From: JP Massar
Subject: Re: how can I do this with macros?
Date: 
Message-ID: <3f3fae0a.204760070@netnews.comcast.net>
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))))
From: Paul F. Dietz
Subject: Re: how can I do this with macros?
Date: 
Message-ID: <-bCcnZdkhMDbVKKiXTWJhA@dls.net>
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
From: Wade Humeniuk
Subject: Re: how can I do this with macros?
Date: 
Message-ID: <YYP%a.67927$LD6.1515843@news0.telusplanet.net>
"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
From: Paul F. Dietz
Subject: Re: how can I do this with macros?
Date: 
Message-ID: <Ly6dna44_6PlUKKiXTWJjg@dls.net>
Wade Humeniuk wrote:
> "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>

Um, right.  Didn't read closely enough.

	Paul