[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Anaphoric macros: increase visibility
From: |
Tino Calancha |
Subject: |
Re: Anaphoric macros: increase visibility |
Date: |
Sun, 15 Jan 2017 19:24:56 +0900 (JST) |
User-agent: |
Alpine 2.20 (DEB 67 2015-01-07) |
Hi Michael,
I sometimes think that `if-let*' would be a better name for `if-let'
because bindings can refer (and naturally most of the time do) refer to other
bindings.
+1
I also often think that `and-let' (or `and-let*' ...) would be a better name
for `when-let' (because the expressions for the bindings are `and'ed,
sot the whole thing feels more like `and' to me).
I am in the middle of the 2 names:
*) and-let* suggests me that the bindings are `and'ed
**) but when-let* suggests me that the second argument is a list of
expressions, i.e., not just a form.
(pcase-let ((`(,a ,b) '(1 2 3)))
(list a b))
==> (1 2)
although the pattern doesn't match.
I can be bitten with that pitfall as well.
I think I would prefer something like
#+begin_src emacs-lisp
(defmacro pwhen (pairs &rest body)
(declare (indent 1))
`(pcase nil ((and ,@(mapcar (lambda (pair) (cons 'let pair)) pairs)) ,@body)))
#+end_src
It might be useful.
I'm using `when-let' and `if-let' a lot, but I'm still not sure
in which direction we should develop this approach.
I think we should have an imagination of where the travel should
end before adding more *-let macros.
A possible starting point is puting all together in
subr-x.el after a heading
;;; Anaphoric macros.
and perform the improvements in naming discussed in this thread:
1) Move `ibuffer-aif', `ibuffer-awhen' to subr-x.el and rename as
`if-it', `when-it'. Add aliases to them `aif', `awhen'.
2) `if-let' --> `if-let*'. Add alias `if-let' for
backward compatibility.
3) `when-let' --> `when-let*' (or `and-let*'). Add alias.
Once they are all together is easier to see what macro is missing
which could be useful.
Tino
- Anaphoric macros: increase visibility, Tino Calancha, 2017/01/13
- Re: Anaphoric macros: increase visibility, Michael Heerdegen, 2017/01/13
- Re: Anaphoric macros: increase visibility, Tino Calancha, 2017/01/14
- Re: Anaphoric macros: increase visibility, Michael Heerdegen, 2017/01/14
- On the naming/behavior of {if, when}-let (was Re: Anaphoric macros: increase visibility), Mark Oteiza, 2017/01/14
- Re: Anaphoric macros: increase visibility, Michael Heerdegen, 2017/01/14
- Re: Anaphoric macros: increase visibility,
Tino Calancha <=
- Re: Anaphoric macros: increase visibility, Stefan Monnier, 2017/01/15
- Re: Anaphoric macros: increase visibility, Tino Calancha, 2017/01/15
- Re: Anaphoric macros: increase visibility, Stefan Monnier, 2017/01/15
Re: Anaphoric macros: increase visibility, Dmitri Paduchikh, 2017/01/14
- Re: Anaphoric macros: increase visibility, Tino Calancha, 2017/01/14
- Re: Anaphoric macros: increase visibility, Dmitri Paduchikh, 2017/01/14
- Re: Anaphoric macros: increase visibility, Michael Heerdegen, 2017/01/14
- Re: Anaphoric macros: increase visibility, Dmitri Paduchikh, 2017/01/14
- Re: Anaphoric macros: increase visibility, Michael Heerdegen, 2017/01/14