unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* let-alias
@ 2020-05-06 18:50 Helmut Eller
  2020-05-06 20:31 ` let-alias Philipp Stephani
  0 siblings, 1 reply; 7+ messages in thread
From: Helmut Eller @ 2020-05-06 18:50 UTC (permalink / raw)
  To: emacs-devel

After the recent discussion about namespaces, it occurred to me that it
would be useful to have a special form that allows one to create
lexically scoped aliases for function bindings.

The idea is quite simple and is supposed to provide a locally scoped
version of defalias.  A possible syntax would be:

  (let-alias ((new-name old-name) ...)
     body...)

Inside BODY, wherever NEW-NAME is used as function name it should
produce the same result as using OLD-NAME would.  E.g.

  (let-alias ((c car)) (c x))            ===  (car x)
  (let-alias ((c car)) #'c)              ===  #'car
  (let-alias ((c car)) (setf (c x) y))   ===  (setf (car x) y)
  (let-alias ((when-not unless)) (when-not x y)) === (unless x y)

Would somebody be opposed to such a new special form? Or better yet, is
there already some way to achieve this?

Helmut




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: let-alias
  2020-05-06 18:50 let-alias Helmut Eller
@ 2020-05-06 20:31 ` Philipp Stephani
  2020-05-06 20:39   ` let-alias Daniel Colascione
  2020-05-06 21:27   ` let-alias Helmut Eller
  0 siblings, 2 replies; 7+ messages in thread
From: Philipp Stephani @ 2020-05-06 20:31 UTC (permalink / raw)
  To: Helmut Eller; +Cc: Emacs developers

Am Mi., 6. Mai 2020 um 20:51 Uhr schrieb Helmut Eller <eller.helmut@gmail.com>:
>
> After the recent discussion about namespaces, it occurred to me that it
> would be useful to have a special form that allows one to create
> lexically scoped aliases for function bindings.
>
> The idea is quite simple and is supposed to provide a locally scoped
> version of defalias.  A possible syntax would be:
>
>   (let-alias ((new-name old-name) ...)
>      body...)
>
> Inside BODY, wherever NEW-NAME is used as function name it should
> produce the same result as using OLD-NAME would.  E.g.
>
>   (let-alias ((c car)) (c x))            ===  (car x)
>   (let-alias ((c car)) #'c)              ===  #'car
>   (let-alias ((c car)) (setf (c x) y))   ===  (setf (car x) y)
>   (let-alias ((when-not unless)) (when-not x y)) === (unless x y)
>
> Would somebody be opposed to such a new special form? Or better yet, is
> there already some way to achieve this?


If you don't mind the quoting, you can use (cl-flet ((c #'car)) ...)



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: let-alias
  2020-05-06 20:31 ` let-alias Philipp Stephani
@ 2020-05-06 20:39   ` Daniel Colascione
  2020-05-06 21:29     ` let-alias Helmut Eller
  2020-05-06 21:27   ` let-alias Helmut Eller
  1 sibling, 1 reply; 7+ messages in thread
From: Daniel Colascione @ 2020-05-06 20:39 UTC (permalink / raw)
  To: Philipp Stephani, Helmut Eller; +Cc: Emacs developers

On 5/6/20 1:31 PM, Philipp Stephani wrote:
> Am Mi., 6. Mai 2020 um 20:51 Uhr schrieb Helmut Eller <eller.helmut@gmail.com>:
>>
>> After the recent discussion about namespaces, it occurred to me that it
>> would be useful to have a special form that allows one to create
>> lexically scoped aliases for function bindings.
>>
>> The idea is quite simple and is supposed to provide a locally scoped
>> version of defalias.  A possible syntax would be:
>>
>>    (let-alias ((new-name old-name) ...)
>>       body...)

Isn't that just symbol-macrolet?



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: let-alias
  2020-05-06 20:31 ` let-alias Philipp Stephani
  2020-05-06 20:39   ` let-alias Daniel Colascione
@ 2020-05-06 21:27   ` Helmut Eller
  1 sibling, 0 replies; 7+ messages in thread
From: Helmut Eller @ 2020-05-06 21:27 UTC (permalink / raw)
  To: Philipp Stephani; +Cc: Emacs developers

On Wed, May 06 2020, Philipp Stephani wrote:

>> Inside BODY, wherever NEW-NAME is used as function name it should
>> produce the same result as using OLD-NAME would.  E.g.
>>
>>   (let-alias ((c car)) (c x))            ===  (car x)
>>   (let-alias ((c car)) #'c)              ===  #'car
>>   (let-alias ((c car)) (setf (c x) y))   ===  (setf (car x) y)
>>   (let-alias ((when-not unless)) (when-not x y)) === (unless x y)
>>
>> Would somebody be opposed to such a new special form? Or better yet, is
>> there already some way to achieve this?
>
>
> If you don't mind the quoting, you can use (cl-flet ((c #'car)) ...)

Hmm, didn't even know that cl-flet had this feature.  But the
bytecode for

  (defun foo (x)
    (cl-flet ((c #'car))
      (c x)))
  
is

byte code for foo:
  doc:   ...
  args: (arg1)
0	constant  car
1	dup	  
2	stack-ref 2
3	call	  1
4	return	  

while the bytecdoe for

(defun bar (x)
  (car x))

is

byte code for bar:
  doc:   ...
  args: (arg1)
0	dup	  
1	car	  
2	return	  

So it's obviously not doing what one would expect from an (zero cost)
alias.  cl-flet also doesn't seem to work for the (setf (c x) ...)
example.

Helmut



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: let-alias
  2020-05-06 20:39   ` let-alias Daniel Colascione
@ 2020-05-06 21:29     ` Helmut Eller
  2020-05-06 21:30       ` let-alias Daniel Colascione
  0 siblings, 1 reply; 7+ messages in thread
From: Helmut Eller @ 2020-05-06 21:29 UTC (permalink / raw)
  To: Daniel Colascione; +Cc: Philipp Stephani, Emacs developers

On Wed, May 06 2020, Daniel Colascione wrote:

>>>    (let-alias ((new-name old-name) ...)
>>>       body...)
>
> Isn't that just symbol-macrolet?

No, symbol-macrolet works on variable names, not for function names.

Helmut



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: let-alias
  2020-05-06 21:29     ` let-alias Helmut Eller
@ 2020-05-06 21:30       ` Daniel Colascione
  2020-05-06 21:34         ` let-alias Helmut Eller
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Colascione @ 2020-05-06 21:30 UTC (permalink / raw)
  To: Helmut Eller; +Cc: Philipp Stephani, Emacs developers

On May 6, 2020 2:29:35 PM Helmut Eller <eller.helmut@gmail.com> wrote:

> On Wed, May 06 2020, Daniel Colascione wrote:
>
>>>> (let-alias ((new-name old-name) ...)
>>>> body...)
>>
>> Isn't that just symbol-macrolet?
>
> No, symbol-macrolet works on variable names, not for function names.


Regular macrolet then?






^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: let-alias
  2020-05-06 21:30       ` let-alias Daniel Colascione
@ 2020-05-06 21:34         ` Helmut Eller
  0 siblings, 0 replies; 7+ messages in thread
From: Helmut Eller @ 2020-05-06 21:34 UTC (permalink / raw)
  To: Daniel Colascione; +Cc: Philipp Stephani, Emacs developers

On Wed, May 06 2020, Daniel Colascione wrote:

>> No, symbol-macrolet works on variable names, not for function names.
>
> Regular macrolet then?

Macrolet wouldn't work for the #'c example.

Helmut



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-05-06 21:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-06 18:50 let-alias Helmut Eller
2020-05-06 20:31 ` let-alias Philipp Stephani
2020-05-06 20:39   ` let-alias Daniel Colascione
2020-05-06 21:29     ` let-alias Helmut Eller
2020-05-06 21:30       ` let-alias Daniel Colascione
2020-05-06 21:34         ` let-alias Helmut Eller
2020-05-06 21:27   ` let-alias Helmut Eller

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).