unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Pip Cet <pipcet@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: "Basil L. Contovounesios" <contovob@tcd.ie>,
	Lars Ingebrigtsen <larsi@gnus.org>,
	emacs-devel@gnu.org
Subject: Re: Always-true predicate?
Date: Sat, 20 Feb 2021 09:40:38 +0000	[thread overview]
Message-ID: <CAOqdjBcPbXvGHWNY-K4UBS=Z=4G=zriEcZFnJgbcATMQz5WO_g@mail.gmail.com> (raw)
In-Reply-To: <jwv1rdb6d7j.fsf-monnier+emacs@gnu.org>

On Fri, Feb 19, 2021 at 8:11 PM Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> >> > (f a b c &rest d)
> >> > rather than
> >> > (apply #'f a b c d)
> >> I don't think it's sufficiently nicer to justify making such a change,
> >
> > I think "usage mimics declaration" is a very important concept,
>
> I generally agree and the above syntax is indeed satisfactory from that
> point of view (and funnily enough Scheme's neat (lambda (x . y) body)
> syntax (which is arguably inspired by a similar desire) does not enjoy
> such a nice equivalent at call sites since (f x . (append a b)) can't
> be distinguished from (f x append a . b)).

I discovered this the hard way :-)

> >> OTOH, the nice thing about `apply` is that it's just a function: no
> >> special treatment, no new syntax, nothing.  Try `grep apply
> >> lisp/emacs-lisp/bytecomp.el` and see how it really needs no
> >> special treatment.
> > ...but it gets that special treatment, which is why (apply #'or) is
> > mis-compiled.
>
> Actually, it's not the compiler, it's the optimizer.

I didn't say "by bytecomp.el", I only said it's mis-compiled. Which it
is. By the optimizer. Which is part of the compiler.

> [ Yes, it's a nitpick, but nevertheless...

If you think the optimizer isn't part of the byte compiler, please
change the first line of byte-opt.el which says it is ;-)

>   Also, I'm not completely sure in which sense it "miscompiles" it,
>   since it can't be compiled correctly, AFAIK.  ]

???

It's perfectly valid ELisp. It should throw. It doesn't.

> >> I'd rather reduce the use of `&rest` and `apply` than try to make it
> >> more sexy, since it's fundamentally quite inefficient
> > I think the inefficiency is fundamental to "apply", not to "&rest".
> > When you call a known procedure all the packing and unpacking of
> > arguments can be inlined...
>
> IMO it's more fundamental to `&rest` because the callee can rely on the
> `&rest` list being a fresh new list (it can safely perform destructive
> update on it).

So to avoid having to cons up a new list you have to know about the
callee to know it doesn't do that, which apply prevents you from
doing.

> > I think we're back to a fundamental question here: if I understand
> > correctly, to you, an ELisp function is fundamentally of the "take a
> > list, return a Lisp object or throw" type, as though it were defined
> > like this:
> >
> > (defan f args (if (/= (length args) 2) (throw
> > 'wrong-number-of-arguments)) (+ (car args) (cadr args)))
>
> Indeed.

Looking forward to your patch removing all argument names from defuns
everywhere ;-)

I'd like to know what equivalence relation you're using when you say
two bare functions f and g are "the same".

I'm pretty sure it's not any of the following:
- their defuns are the same
- they produce the same values for the same inputs
- they produce the same values for the same inputs at the same complexity

> > In your world, (lambda (&rest args) (apply #'f args)) is the same as
> > f. In my world, we have "func-arity", to which it isn't.
>
> In my view, a function value of the form (closure ...) or (lambda ...)
> or #[...] has arity, but a function value represented by a SYMBOL does
> not because it can change at any time.

In my view, every callable function has arity, which can change at any
time in the case of functions that are symbols (which might become
uncallable, too). (It can also change for closures or lambdas if their
underlying lists are mutable).

It seems obvious to me that if f and g are "the same", (func-arity f)
and (func-arity g) should return equal cons cells. That means unless f
is a subr of arity (0 . many), f is not the same as (lambda (&rest
args) (apply #'f args)).

BTW, I made a mistake in my previous email:

(f a &rest b c) should be equivalent to (apply #'f a (append b (list
c))). No zips, and no spreadification of the last argument.

Pip



  reply	other threads:[~2021-02-20  9:40 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-17 12:01 Always-true predicate? Lars Ingebrigtsen
2021-02-17 12:31 ` Andrea Corallo via Emacs development discussions.
2021-02-17 12:40   ` Lars Ingebrigtsen
2021-02-17 16:59     ` Barry Fishman
2021-02-19 15:24   ` Stefan Kangas
2021-02-17 13:16 ` Basil L. Contovounesios
2021-02-17 18:56   ` Pip Cet
2021-02-17 19:19     ` Lars Ingebrigtsen
2021-02-17 19:31       ` Pip Cet
2021-02-17 19:37         ` Lars Ingebrigtsen
2021-02-17 20:18           ` Teemu Likonen
2021-02-17 22:25             ` [External] : " Drew Adams
2021-02-17 23:04               ` Basil L. Contovounesios
2021-02-17 23:13                 ` Drew Adams
2021-02-17 23:01             ` Stefan Monnier
2021-02-19 11:27               ` Pip Cet
2021-02-19 15:07                 ` Stefan Monnier
2021-02-19 19:04                   ` Pip Cet
2021-02-19 20:11                     ` Stefan Monnier
2021-02-20  9:40                       ` Pip Cet [this message]
2021-02-20 13:58                         ` Stefan Monnier
2021-02-19  5:39 ` Richard Stallman
2021-02-19  8:52   ` Robert Pluim
2021-02-19  9:10     ` Eli Zaretskii
2021-02-19 12:12       ` Eli Zaretskii
2021-02-19 12:52       ` Stefan Kangas
2021-02-19 13:00         ` Lars Ingebrigtsen
2021-02-19 13:34         ` Eli Zaretskii
2021-02-19 13:40           ` Lars Ingebrigtsen
2021-02-19 13:53             ` Eli Zaretskii
2021-02-19 14:05               ` Lars Ingebrigtsen
2021-02-19 18:04                 ` [External] : " Drew Adams
2021-02-19 14:42             ` Stefan Monnier
2021-02-20 12:47               ` Lars Ingebrigtsen
2021-02-20 12:49                 ` Lars Ingebrigtsen
2021-02-20 14:03                   ` Stefan Monnier
2021-02-20 14:20                     ` Lars Ingebrigtsen
2021-02-20 14:55                       ` Stefan Monnier
2021-02-20 15:05                         ` Lars Ingebrigtsen
2021-02-20 15:21                           ` Stefan Monnier
2021-02-21 12:50                             ` Robert Pluim
2021-02-21 13:04                             ` Lars Ingebrigtsen
2021-02-19 15:09           ` Stefan Kangas
2021-02-19 15:22             ` Eli Zaretskii
2021-02-19 18:17               ` [External] : " Drew Adams
2021-02-19 18:41                 ` Eli Zaretskii
2021-02-22  5:02       ` chad
2021-02-22 15:20         ` Eli Zaretskii
2021-02-22 23:07           ` chad
2021-02-21  6:12     ` Richard Stallman
2021-02-21 15:12       ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOqdjBcPbXvGHWNY-K4UBS=Z=4G=zriEcZFnJgbcATMQz5WO_g@mail.gmail.com' \
    --to=pipcet@gmail.com \
    --cc=contovob@tcd.ie \
    --cc=emacs-devel@gnu.org \
    --cc=larsi@gnus.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).