[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: let-alias
From: |
Helmut Eller |
Subject: |
Re: let-alias |
Date: |
Wed, 06 May 2020 23:27:40 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
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
- let-alias, Helmut Eller, 2020/05/06
- Re: let-alias,
Helmut Eller <=