emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Always-true predicate?


From: Pip Cet
Subject: Re: Always-true predicate?
Date: Fri, 19 Feb 2021 11:27:52 +0000

On Wed, Feb 17, 2021 at 11:01 PM Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
> > Seriously: I remember one case when I tried to find CONSTANTLY or
> > similar but failed. I wrote some LAMBDA form. No big deal.
>
> Maybe we should let `lambda` take arguments like Scheme does, i.e.
> (lambda (a b . c) FOO) instead of (lambda (a b &rest c) FOO), and in that
> case we could simple use "lambda _" as a shorthand for "constantly".

That would break things like pcase-lambda, though: we would no longer
be able to generalize lambda meaningfully.

TL;DR - let's make (lambda (&rest) t) valid for the universal
predicate and leave it at that.

Anyway, my problem with variadic functions isn't defining them, it's
calling them. I think I should be able to say

(f a b c &rest d)

rather than

(apply #'f a b c d)

which would make usage mimic declaration. Kind of like JavaScript's
... operator (and in fact that would be a better name for it than
&rest, IMHO, though of course it should be a symbol rather than extra
syntax). (For extra fun, consider

(f &rest a &rest b) = (apply #'f (append a b))

and

(f &rest keywords values) = (apply #'f (zip keywords values))

(I don't like apply, even when it's not (apply nil), mostly because

(apply #'f 'a 'b nil)

isn't necessarily equivalent to

(f 'a 'b) [1])

As for the universal predicate, I'd like to be able to write (lambda
(&rest) t), which would save two characters. (lambda (...) t) would
save another one :-) )

And if we can require optional arguments, why can't we provide them
optionally? For example, let's say in Emacs 33 we want to expand
copy-marker with a new argument to more clearly describe how the
marker repositions itself relative to other markers (or implicit)
markers at the same character position. But (copy-marker marker nil
&optional 'something) would work in Emacs 32 (which would include the
optionally-provided argument extension), and be equivalent to
(copy-marker marker nil) there.

Pip

[1] - if f is a macro, for example. The byte compiler has a fun bug if
you feed it this input:

(defun eval-then-throw (a b)
  (apply #'or a (eval b) nil))

(eval-then-throw t '(message "printme"))
(byte-compile 'eval-then-throw)
(eval-then-throw t '(message "printme"))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]