emacs-devel
[Top][All Lists]
Advanced

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

Re: Docs for &optional and &rest arguments together


From: tomas
Subject: Re: Docs for &optional and &rest arguments together
Date: Thu, 31 Dec 2020 12:26:34 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

On Thu, Dec 31, 2020 at 07:55:26AM +0000, arthur miller wrote:
> I don't read it says both c and d are required when &rest is also used.

You just have to squint the other way .-)

They are not "required". They are provided -- in the call. It's just
that c is served first, d next, and all the rest (if any) goes to e:

  (defun foo (a b &optional c d &rest e))
    ...)

If called like

  (foo 42)
        => error (missing arg
  (foo 42 55)
        => a -> 42 b -> 55 c -> nil d -> nil e -> nil
  (foo 42 55 67)
        => a -> 42 b -> 55 c -> 67 d -> nil e -> nil
  (foo 42 55 67 92)
        => a -> 42 b -> 55 c -> 67 d -> 92 e -> nil
  (foo 42 55 67 92 117)
        => a -> 42 b -> 55 c -> 67 d -> 92 e -> (117)
  (foo 42 55 67 92 117 122)
        => a -> 42 b -> 55 c -> 67 d -> 92 e -> (117)
  (foo 42 55 67 92 117 122 131)
        => a -> 42 b -> 55 c -> 67 d -> 92 e -> (117 131)
  ...

Thing is, when calling the function you have /no way/ to express
which arg you are targeting [1]. This is what the doc is trying
to tell us with

  "If one or two more arguments are provided, c and d are
   bound to them respectively; any arguments after the first
   four are collected into a list and e is bound to that list."

As happens to Lars, to me this snippet seems to be as clear as
it gets. But there seems to be something you are stumbling over.
Since we can't see it, it's on you to open our eyes :)

How could that be put more clearly?

Cheers

[1] That's what "keyword arguments" are for. Emacs lisp
   doesn't come "natively" with keyword arguments, but
   this being a Lisp, they just can be "made" (cf. the
   CL library for one implementation).

 - t

Attachment: signature.asc
Description: Digital signature


reply via email to

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