From: Sungwoo Lim
Subject: [Q] How can I use same definition with different name?
Date: 
Message-ID: <sungwoo-0204011729250001@gorecki.cad.strath.ac.uk>
Hello,

I would like to use a definition in a different place with different name.
e.g.

(defun template-def (a b c)
   (* a b c))

want to use as

(difname1 a1 a2 a3)
(difname2 b1 b2 b3) 
so on....

What should I do to enable this?
Thanks for your help.

Sungwoo

From: Geoff Summerhayes
Subject: Re: [Q] How can I use same definition with different name?
Date: 
Message-ID: <tchc4ojebdel96@corp.supernews.com>
"Sungwoo Lim" <·······@cad.strath.ac.uk> wrote in message ·····························@gorecki.cad.strath.ac.uk...
> Hello,
>
> I would like to use a definition in a different place with different name.
> e.g.
>
> (defun template-def (a b c)
>    (* a b c))
>
> want to use as
>
> (difname1 a1 a2 a3)
> (difname2 b1 b2 b3)
> so on....
>
> What should I do to enable this?
> Thanks for your help.
>

I'm guessing

(defmacro diffname1 (&rest args)
   `(template-def ,@args))

or

(let ((diffname1 #'template-def))
   (funcall diffname1 a1 a2 a3))

or even

(defun diffname1 (&rest args) (apply #'template-def args))

aren't quite what you're looking for. Of course, my big question
is "Why?"

Geoff
From: Sungwoo Lim
Subject: Re: [Q] How can I use same definition with different name?
Date: 
Message-ID: <sungwoo-0304011023450001@gorecki.cad.strath.ac.uk>
In article <··············@corp.supernews.com>, "Geoff Summerhayes"
<·············@hNoOtSmPaAiMl.com> wrote:
 
> (defmacro diffname1 (&rest args)
>    `(template-def ,@args))
>
This works.
 

> (let ((diffname1 #'template-def))
>    (funcall diffname1 a1 a2 a3))
This one got the error as

 Error: Unbound variable: A1 .
 While executing: #<Anonymous Function #x1022F816>

 
 
> (defun diffname1 (&rest args) (apply #'template-def args))
this doesn't works if I defined 'diffname1' as defmacro.
It gives me the error as 

 Error: The macro DIFFNAME1 is being redefined as a function.
 While executing: FSET

I don't know why it gives error rather than warning..

 
> aren't quite what you're looking for. Of course, my big question
> is "Why?"

Yeah, it is kinda what I am looking for. The reason I am trying to do this
is that the definition 'template-def' is not small portion, and I need use
that more than once with a different name and different variables. 

Thanks for your help. =)

Sungwoo

-- 

--
<^)++<
From: Kent M Pitman
Subject: Re: [Q] How can I use same definition with different name?
Date: 
Message-ID: <sfwitkmb3dr.fsf@world.std.com>
·······@cad.strath.ac.uk (Sungwoo Lim) writes:

> In article <··············@corp.supernews.com>, "Geoff Summerhayes"
> <·············@hNoOtSmPaAiMl.com> wrote:
>  
> > (defmacro diffname1 (&rest args)
> >    `(template-def ,@args))
> >
> This works.
>  
> 
> > (let ((diffname1 #'template-def))
> >    (funcall diffname1 a1 a2 a3))
> This one got the error as
> 
>  Error: Unbound variable: A1 .
>  While executing: #<Anonymous Function #x1022F816>

Perhaps you're doing it at toplevel.  This is not a substitute for the
defmacro, but rather a substitute for the call (diffname1 a1 a2 a3) at
the point where a1, a2, and a3 are supposed to have been bound or else
your other examples wouldn't have worked either.

> > (defun diffname1 (&rest args) (apply #'template-def args))
> this doesn't works if I defined 'diffname1' as defmacro.
> It gives me the error as 
> 
>  Error: The macro DIFFNAME1 is being redefined as a function.
>  While executing: FSET
> 
> I don't know why it gives error rather than warning..

Most implementations that do this have a variable controlling it.  Try
(apropos "redef") to see if there's a global variable with a name like
*WARN-ON-REDEFINITION* or some such thing.  Sometimes it will not just
be boolean but rather will have several options, like NIL, :WARN or
:ERROR...  All of this is implementation-dependent; any similarity is
only because some vendor saw what some other one did and liked it
enough to either copy the idea or to almost do so.
  
From: Sungwoo Lim
Subject: Re: [Q] How can I use same definition with different name?
Date: 
Message-ID: <sungwoo-0304011324570001@gorecki.cad.strath.ac.uk>
In article <···············@world.std.com>, Kent M Pitman
<······@world.std.com> wrote:

> Perhaps you're doing it at toplevel.  This is not a substitute for the
> defmacro, but rather a substitute for the call (diffname1 a1 a2 a3) at
> the point where a1, a2, and a3 are supposed to have been bound or else
> your other examples wouldn't have worked either.

I see.
 
> Most implementations that do this have a variable controlling it.  Try
> (apropos "redef") to see if there's a global variable with a name like
> *WARN-ON-REDEFINITION* or some such thing.  Sometimes it will not just
> be boolean but rather will have several options, like NIL, :WARN or
> :ERROR...  All of this is implementation-dependent; any similarity is
> only because some vendor saw what some other one did and liked it
> enough to either copy the idea or to almost do so.

4 > (apropos "redef")
CCL::%CLASS-REDEFINED-INITARGS, Def: MACRO FUNCTION,  Value: 18
 CCL::REDEFINE-KERNEL-FUNCTION, Def: FUNCTION
 CCL::REDEFINE-KERNEL-METHOD, Def: FUNCTION
 CCL::REDEFINE-STANDARD-CLASS, Def: MACRO FUNCTION
 CCL::REDEFINED-INITARGS
CCL::%REDEFMETHOD, Def: FUNCTION
      UPDATE-INSTANCE-FOR-REDEFINED-CLASS, Def: STANDARD-GENERIC-FUNCTION
 CCL::UPDATE-REDEFINED-LONG-METHOD-COMBINATIONS, Def: FUNCTION
 CCL::UPDATE-REDEFINED-SHORT-METHOD-COMBINATIONS, Def: FUNCTION
     *WARN-IF-REDEFINE*,  Value: T
     *WARN-IF-REDEFINE-KERNEL*,  Value: T
4 >
   

Aha, I see. hmm... mine is *WARN-IF-REDEFINE*...
but still gives me error.. strange...
Anyway, thanks alot. =)

Sungwoo

-- 

--
<^)++<
From: Tim Bradshaw
Subject: Re: [Q] How can I use same definition with different name?
Date: 
Message-ID: <ey3ofuf5ieg.fsf@tfeb.org>
* Sungwoo Lim wrote:
> Hello,
> I would like to use a definition in a different place with different name.
> e.g.

> (defun template-def (a b c)
>    (* a b c))

> want to use as

> (difname1 a1 a2 a3)
> (difname2 b1 b2 b3) 

(setf (symbol-function 'difname1) (symbol-function 'template-def)).

or, if you do it a lot.

(defmacro defalias (f1 f2)
  `(setf (symbol-function ',f1) (symbol-function ',f2)))

(defalias difname1 template-def)
(defalias difname1 template-def)

Note I'm not really sure what happens if you redefine TEMPLATE-DEF --
I think DIFNAME still refers to the old definition (in fact I'm fairly
sure of this, but I think that Genera (?) made this `work'.

All this code is untested.

--tim
From: Sungwoo Lim
Subject: Re: [Q] How can I use same definition with different name?
Date: 
Message-ID: <sungwoo-0304011035070001@gorecki.cad.strath.ac.uk>
In article <···············@tfeb.org>, Tim Bradshaw <···@tfeb.org> wrote:

> (setf (symbol-function 'difname1) (symbol-function 'template-def)).
> 
> or, if you do it a lot.
> 
> (defmacro defalias (f1 f2)
>   `(setf (symbol-function ',f1) (symbol-function ',f2)))
> 
> (defalias difname1 template-def)
> (defalias difname1 template-def)
> 
> Note I'm not really sure what happens if you redefine TEMPLATE-DEF --
> I think DIFNAME still refers to the old definition (in fact I'm fairly
> sure of this, but I think that Genera (?) made this `work'.
> 
> All this code is untested.
> 
> --tim

It works. =)

Thanks alot.

Sungwoo

-- 

--
<^)++<