all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Docs for &optional and &rest arguments together
@ 2020-12-29 13:26 Arthur Miller
  2020-12-29 15:10 ` Adam Porter
  2020-12-30  3:12 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 23+ messages in thread
From: Arthur Miller @ 2020-12-29 13:26 UTC (permalink / raw)
  To: emacs-devel


I like 'with-*' idiom in Lisp, and I have written a smal macro for
myself to work with files, based on with-temp-file macro.

The Manual says I can have both optional and rest arguments togheter,
which we can: 

(required-vars…
 [&optional [optional-vars…]]
 [&rest [rest-var]])

But when I use it, I still have to pass a nil for the "optional"
argument, which I think is also not so strange either, otherwise how
will Emacs now where "optional" argument list ends and where "rest"
argument list starts? No?

When I read the manual:

"A call to the function requires one actual argument for each of the
required-vars. There may be actual arguments for zero or more of the
optional-vars, and there cannot be any actual arguments beyond that
unless the lambda list uses &rest. In that case, there may be any number
of extra actual arguments.

If actual arguments for the optional and rest variables are omitted,
then they always default to nil."

https://www.gnu.org/software/emacs/manual/html_node/elisp/Argument-List.html

I get the impression that I actually can omit the optional argument(s)
even when followed by the &rest keyword. It is probably only the case
when optional arguments *are not* followed by the &rest keyword. I don't
see that captured by the documentation, at least not very clearly.

After the experience with add-to-list I am not offering any patches for
the docs. I am just pointing it out how I perceive it. If I am wrong
about, I would be actually happy to see how to use both &optional and
&rest and not have to specify the "optional" argument when I call the macro.

For the illustration of what I describe above, here is the macro:

(defmacro with-file (file &optional operation &rest body)
  (declare (indent 1) (debug t))
  `(let ((op ,operation)
         (buffer (get-buffer-create ,file)))
     (unless op
       (setq op 'append))
     (unwind-protect
         (prog1 
             (with-current-buffer buffer
                   (cond ((equal op 'apend)
                          (goto-char (point-min))
                          (insert-file-contents ,file)
                          (goto-char (point-max))
                          ,@body)
                         ((equal op 'prepend)
                          ,@body
                          (goto-char (point-max))
                          (insert-file-contents ,file))
                         (t ;; overwrite file
                          ,@body)))
	   (with-current-buffer buffer
	     (write-region nil nil ,file nil 0)))
       (and (buffer-name buffer)
            (kill-buffer buffer)))))

And when calling, there is no way to omit the "optional" nil:

(with-file "some-test" nil
           (insert "hello world"))

(with-file "some-test" 'prepend
           (insert "I am before Hello world!")
           (newline))

(with-file "some-test" 'apend
           (newline)
           (insert "I am after Hello world!"))



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Docs for &optional and &rest arguments together
  2020-12-29 13:26 Docs for &optional and &rest arguments together Arthur Miller
@ 2020-12-29 15:10 ` Adam Porter
  2020-12-29 17:06   ` arthur miller
  2021-01-01 14:33   ` Arthur Miller
  2020-12-30  3:12 ` Lars Ingebrigtsen
  1 sibling, 2 replies; 23+ messages in thread
From: Adam Porter @ 2020-12-29 15:10 UTC (permalink / raw)
  To: emacs-devel

This doesn't exactly answer your question, but here's an alternative you
might be interested in: I wrote a similar macro a while back, and I
tried to follow CL-style arguments by using a list of options.

https://github.com/alphapapa/elexandria/blob/83a1b08d0711fdce07a5b33525535cc3a457c6ee/elexandria.el#L105

Here's the source code:

(cl-defmacro with-file-buffer (path options &body body)
  "Insert contents of file at PATH into a temp buffer, and evaluate and return the value of BODY in it.
OPTIONS is a plist accepting the following options:

`:must-exist': If non-nil, raise an error if no file exists at
PATH.

`:write': If non-nil, write the contents of the buffer to file at
PATH after evaluating BODY.

`:overwrite': If nil (or unset), raise an error instead of
overwriting an existing file at PATH.  If `ask', ask for
confirmation before overwriting an existing file.  If t,
overwrite a file at PATH unconditionally.

`:append': Passed to function `write-region', which see.

`:visit':  Passed to function `write-region', which see."
  (declare (indent 2))
  `(with-temp-buffer
     (if (file-readable-p ,path)
         (insert-file-contents ,path)
       (when ,(plist-get options :must-exist)
         (error "File not readable: %s" ,path)))
     (prog1
         (progn
           ,@body)
       ,(when (plist-get options :write)
          `(write-region nil nil path
                         ,(plist-get options :append)
                         ,(plist-get options :visit)
                         ,(pcase-exhaustive (plist-get options :overwrite)
                            ('nil ''excl)
                            ((or 'ask ''ask) ''ask)
                            ('t nil)))))))




^ permalink raw reply	[flat|nested] 23+ messages in thread

* RE: Docs for &optional and &rest arguments together
  2020-12-29 15:10 ` Adam Porter
@ 2020-12-29 17:06   ` arthur miller
  2021-01-01 14:33   ` Arthur Miller
  1 sibling, 0 replies; 23+ messages in thread
From: arthur miller @ 2020-12-29 17:06 UTC (permalink / raw)
  To: Adam Porter, emacs-devel@gnu.org

[-- Attachment #1: Type: text/plain, Size: 2222 bytes --]

Thx Adam, I'll take a look at it some time.

It wasn't though much of a question, I just wanted to point out that docs miss to make clear a case when optional and rest arguments are used together. Unless I don't misunderstand how it works. Maybe I do :-).






-------- Originalmeddelande --------
Från: Adam Porter <adam@alphapapa.net>
Datum: 2020-12-29 16:11 (GMT+01:00)
Till: emacs-devel@gnu.org
Ämne: Re: Docs for &optional and &rest arguments together

This doesn't exactly answer your question, but here's an alternative you
might be interested in: I wrote a similar macro a while back, and I
tried to follow CL-style arguments by using a list of options.

https://github.com/alphapapa/elexandria/blob/83a1b08d0711fdce07a5b33525535cc3a457c6ee/elexandria.el#L105

Here's the source code:

(cl-defmacro with-file-buffer (path options &body body)
  "Insert contents of file at PATH into a temp buffer, and evaluate and return the value of BODY in it.
OPTIONS is a plist accepting the following options:

`:must-exist': If non-nil, raise an error if no file exists at
PATH.

`:write': If non-nil, write the contents of the buffer to file at
PATH after evaluating BODY.

`:overwrite': If nil (or unset), raise an error instead of
overwriting an existing file at PATH.  If `ask', ask for
confirmation before overwriting an existing file.  If t,
overwrite a file at PATH unconditionally.

`:append': Passed to function `write-region', which see.

`:visit':  Passed to function `write-region', which see."
  (declare (indent 2))
  `(with-temp-buffer
     (if (file-readable-p ,path)
         (insert-file-contents ,path)
       (when ,(plist-get options :must-exist)
         (error "File not readable: %s" ,path)))
     (prog1
         (progn
           ,@body)
       ,(when (plist-get options :write)
          `(write-region nil nil path
                         ,(plist-get options :append)
                         ,(plist-get options :visit)
                         ,(pcase-exhaustive (plist-get options :overwrite)
                            ('nil ''excl)
                            ((or 'ask ''ask) ''ask)
                            ('t nil)))))))



[-- Attachment #2: Type: text/html, Size: 4496 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Docs for &optional and &rest arguments together
  2020-12-29 13:26 Docs for &optional and &rest arguments together Arthur Miller
  2020-12-29 15:10 ` Adam Porter
@ 2020-12-30  3:12 ` Lars Ingebrigtsen
  2020-12-30 12:19   ` Arthur Miller
  1 sibling, 1 reply; 23+ messages in thread
From: Lars Ingebrigtsen @ 2020-12-30  3:12 UTC (permalink / raw)
  To: Arthur Miller; +Cc: emacs-devel

Arthur Miller <arthur.miller@live.com> writes:

> (required-vars…
>  [&optional [optional-vars…]]
>  [&rest [rest-var]])
>
> But when I use it, I still have to pass a nil for the "optional"
> argument, which I think is also not so strange either, otherwise how
> will Emacs now where "optional" argument list ends and where "rest"
> argument list starts? No?

Right.

> If actual arguments for the optional and rest variables are omitted,
> then they always default to nil."
>
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Argument-List.html
>
> I get the impression that I actually can omit the optional argument(s)
> even when followed by the &rest keyword.

The paragraph just below this one, though, describes in detail what
happens with a mixed &optional and &rest argument list, so that's not my
impression when reading that node.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Docs for &optional and &rest arguments together
  2020-12-30  3:12 ` Lars Ingebrigtsen
@ 2020-12-30 12:19   ` Arthur Miller
  2020-12-30 12:54     ` Yuri Khan
  2020-12-31  4:43     ` Lars Ingebrigtsen
  0 siblings, 2 replies; 23+ messages in thread
From: Arthur Miller @ 2020-12-30 12:19 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: emacs-devel

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Arthur Miller <arthur.miller@live.com> writes:
>
>> (required-vars…
>>  [&optional [optional-vars…]]
>>  [&rest [rest-var]])
>>
>> But when I use it, I still have to pass a nil for the "optional"
>> argument, which I think is also not so strange either, otherwise how
>> will Emacs now where "optional" argument list ends and where "rest"
>> argument list starts? No?
>
> Right.
>
>> If actual arguments for the optional and rest variables are omitted,
>> then they always default to nil."
>>
>> https://www.gnu.org/software/emacs/manual/html_node/elisp/Argument-List.html
>>
>> I get the impression that I actually can omit the optional argument(s)
>> even when followed by the &rest keyword.
>
> The paragraph just below this one, though, describes in detail what
> happens with a mixed &optional and &rest argument list, so that's not my
> impression when reading that node.

"A call to the function requires one actual argument for each of the
required-vars. There may be actual arguments for zero or more of the
optional-vars, and there cannot be any actual arguments beyond that
unless the lambda list uses &rest. In that case, there may be any number
of extra actual arguments."

"If actual arguments for the optional and rest variables are omitted,
then they always default to nil. There is no way for the function to
distinguish between an explicit argument of nil and an omitted
argument. However, the body of the function is free to consider nil an
abbreviation for some other meaningful value. This is what substring
does; nil as the third argument to substring means to use the length of
the string supplied."

Which part of the doc does it say that &optional argument when
used together with &rest, makes &optional argument mandatory, i.e. can
not be ommitted when calling a function or macro?



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Docs for &optional and &rest arguments together
  2020-12-30 12:19   ` Arthur Miller
@ 2020-12-30 12:54     ` Yuri Khan
  2020-12-31  4:43     ` Lars Ingebrigtsen
  1 sibling, 0 replies; 23+ messages in thread
From: Yuri Khan @ 2020-12-30 12:54 UTC (permalink / raw)
  To: Arthur Miller; +Cc: Lars Ingebrigtsen, Emacs developers

On Wed, 30 Dec 2020 at 19:20, Arthur Miller <arthur.miller@live.com> wrote:

> Which part of the doc does it say that &optional argument when
> used together with &rest, makes &optional argument mandatory, i.e. can
> not be ommitted when calling a function or macro?

Imagine If This Were Possible:

    (defun foo (bar &optional baz &rest quux)
      "doc"
      nil)  ;; the body is not important

    (foo 3.14 42)       ;; intending baz = 42, quux = nil
    (foo 3.14 "xyzzy")  ;; intending baz = nil, quux = ("xyzzy")

How would the interpreter decide whether you wanted to omit the
&optional argument or the &rest argument?



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Docs for &optional and &rest arguments together
  2020-12-30 12:19   ` Arthur Miller
  2020-12-30 12:54     ` Yuri Khan
@ 2020-12-31  4:43     ` Lars Ingebrigtsen
  2020-12-31  7:55       ` arthur miller
  1 sibling, 1 reply; 23+ messages in thread
From: Lars Ingebrigtsen @ 2020-12-31  4:43 UTC (permalink / raw)
  To: Arthur Miller; +Cc: emacs-devel

Arthur Miller <arthur.miller@live.com> writes:

>> The paragraph just below this one, though, describes in detail what
>> happens with a mixed &optional and &rest argument list, so that's not my
>> impression when reading that node.
>
> "A call to the function requires one actual argument for each of the

No, this bit:

For example, an argument list that looks like this: 

(a b &optional c d &rest e)

binds a and b to the first two actual arguments, which are required. 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.  Thus, if there are only two
arguments, c, d and e are nil; if two or three arguments, d and e are
nil; if four arguments or fewer, e is nil. Note that exactly five
arguments with an explicit nil argument provided for e will cause that
nil argument to be passed as a list with one element, (nil), as with any
other single value for e.


-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 23+ messages in thread

* RE: Docs for &optional and &rest arguments together
  2020-12-31  4:43     ` Lars Ingebrigtsen
@ 2020-12-31  7:55       ` arthur miller
  2020-12-31 11:26         ` tomas
  0 siblings, 1 reply; 23+ messages in thread
From: arthur miller @ 2020-12-31  7:55 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: emacs-devel@gnu.org

[-- Attachment #1: Type: text/plain, Size: 1442 bytes --]

I don't read it says both c and d are required when &rest is also used.


-------- Originalmeddelande --------
Från: Lars Ingebrigtsen <larsi@gnus.org>
Datum: 2020-12-31 05:44 (GMT+01:00)
Till: Arthur Miller <arthur.miller@live.com>
Kopia: emacs-devel@gnu.org
Ämne: Re: Docs for &optional and &rest arguments together

Arthur Miller <arthur.miller@live.com> writes:

>> The paragraph just below this one, though, describes in detail what
>> happens with a mixed &optional and &rest argument list, so that's not my
>> impression when reading that node.
>
> "A call to the function requires one actual argument for each of the

No, this bit:

For example, an argument list that looks like this:

(a b &optional c d &rest e)

binds a and b to the first two actual arguments, which are required. 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.  Thus, if there are only two
arguments, c, d and e are nil; if two or three arguments, d and e are
nil; if four arguments or fewer, e is nil. Note that exactly five
arguments with an explicit nil argument provided for e will cause that
nil argument to be passed as a list with one element, (nil), as with any
other single value for e.


--
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no

[-- Attachment #2: Type: text/html, Size: 2258 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Docs for &optional and &rest arguments together
  2020-12-31  7:55       ` arthur miller
@ 2020-12-31 11:26         ` tomas
  2020-12-31 16:45           ` Drew Adams
  2020-12-31 17:08           ` arthur miller
  0 siblings, 2 replies; 23+ messages in thread
From: tomas @ 2020-12-31 11:26 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1666 bytes --]

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 #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* RE: Docs for &optional and &rest arguments together
  2020-12-31 11:26         ` tomas
@ 2020-12-31 16:45           ` Drew Adams
  2020-12-31 17:04             ` Drew Adams
  2020-12-31 17:28             ` arthur miller
  2020-12-31 17:08           ` arthur miller
  1 sibling, 2 replies; 23+ messages in thread
From: Drew Adams @ 2020-12-31 16:45 UTC (permalink / raw)
  To: tomas, emacs-devel

> > 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:

If someone finds the Elisp doc about lambda lists,
I recommend consulting the Common Lisp doc (CLTL2)
about it.  Common Lisp lambda lists allow more stuff
(&keys, &aux etc.), but for the things that Elisp
has (&optional, &rest) the behavior is the same.

The language in CLTL2 is quite precise.  It too
merits being read carefully, but I think it spells
things out quite clearly.

This is the section about lambda lists, which covers
&optional and &rest:

https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node64.html#SECTION00922000000000000000

With that, plus the Elisp doc, plus this thread,
I think things will become more clear.  HTH.



^ permalink raw reply	[flat|nested] 23+ messages in thread

* RE: Docs for &optional and &rest arguments together
  2020-12-31 16:45           ` Drew Adams
@ 2020-12-31 17:04             ` Drew Adams
  2020-12-31 17:28             ` arthur miller
  1 sibling, 0 replies; 23+ messages in thread
From: Drew Adams @ 2020-12-31 17:04 UTC (permalink / raw)
  To: tomas, emacs-devel

> If someone finds the Elisp doc about lambda lists,

That should have been:

  If someone finds the Elisp doc about lambda lists
  confusing or incomplete, then

> I recommend consulting the Common Lisp doc (CLTL2)
> about it.



^ permalink raw reply	[flat|nested] 23+ messages in thread

* RE: Docs for &optional and &rest arguments together
  2020-12-31 11:26         ` tomas
  2020-12-31 16:45           ` Drew Adams
@ 2020-12-31 17:08           ` arthur miller
  2020-12-31 17:30             ` Daniel Brooks
  2020-12-31 19:40             ` tomas
  1 sibling, 2 replies; 23+ messages in thread
From: arthur miller @ 2020-12-31 17:08 UTC (permalink / raw)
  To: tomas@tuxteam.de, emacs-devel@gnu.org

[-- Attachment #1: Type: text/plain, Size: 2589 bytes --]

It Is flera för me hos it work. What I am saying is that docs does not say that we can't omit "optional" c or d when &rest is used. In the examples you are illustrating with, one can't omit say d and write (foo a b  c  e), both c and d are required, so user has to pass explicitly at least nil if not d is provided: (foo a b c nil e)

Documentation is talking about being able to omit either optional or rest arga, but does not touch on the case when one pass both optional and rest together. In that case optional is not optional any longer.

I don't understand why is it so difficult to see what I am talking about :-).

Anyway: Happy new year's eve and all best in 2021!


-------- Originalmeddelande --------
Från: tomas@tuxteam.de
Datum: 2020-12-31 12:27 (GMT+01:00)
Till: emacs-devel@gnu.org
Ämne: Re: Docs for &optional and &rest arguments together

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 #2: Type: text/html, Size: 4070 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* RE: Docs for &optional and &rest arguments together
  2020-12-31 16:45           ` Drew Adams
  2020-12-31 17:04             ` Drew Adams
@ 2020-12-31 17:28             ` arthur miller
  2020-12-31 18:19               ` Drew Adams
  1 sibling, 1 reply; 23+ messages in thread
From: arthur miller @ 2020-12-31 17:28 UTC (permalink / raw)
  To: Drew Adams, tomas@tuxteam.de, emacs-devel@gnu.org

[-- Attachment #1: Type: text/plain, Size: 1342 bytes --]

The CL link is not documentation, it is an essay, entire novel :-). But interestingly, that do not touch on that case either . I have glanced through though, maybe I am missing it.


-------- Originalmeddelande --------
Från: Drew Adams <drew.adams@oracle.com>
Datum: 2020-12-31 17:48 (GMT+01:00)
Till: tomas@tuxteam.de, emacs-devel@gnu.org
Ämne: RE: Docs for &optional and &rest arguments together

> > 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:

If someone finds the Elisp doc about lambda lists,
I recommend consulting the Common Lisp doc (CLTL2)
about it.  Common Lisp lambda lists allow more stuff
(&keys, &aux etc.), but for the things that Elisp
has (&optional, &rest) the behavior is the same.

The language in CLTL2 is quite precise.  It too
merits being read carefully, but I think it spells
things out quite clearly.

This is the section about lambda lists, which covers
&optional and &rest:

https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node64.html#SECTION00922000000000000000

With that, plus the Elisp doc, plus this thread,
I think things will become more clear.  HTH.


[-- Attachment #2: Type: text/html, Size: 2187 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Docs for &optional and &rest arguments together
  2020-12-31 17:08           ` arthur miller
@ 2020-12-31 17:30             ` Daniel Brooks
  2020-12-31 19:53               ` arthur miller
  2020-12-31 19:40             ` tomas
  1 sibling, 1 reply; 23+ messages in thread
From: Daniel Brooks @ 2020-12-31 17:30 UTC (permalink / raw)
  To: arthur miller; +Cc: tomas@tuxteam.de, emacs-devel@gnu.org

arthur miller <arthur.miller@live.com> writes:

> It Is flera för me hos it work. What I am saying is that docs does not
> say that we can't omit "optional" c or d when &rest is used. In the
> examples you are illustrating with, one can't omit say d and write
> (foo a b c e), both c and d are required, so user has to pass
> explicitly at least nil if not d is provided: (foo a b c nil e)

It has the same behavior even when there is no &rest argument. The
caller cannot omit argument c while still supplying argument d without
inserting a nil: (foo a b d) vs (foo a b nil d). Both c and d are
_optional_, because the caller deson't have to supply them. But it does
have to supply the earlier ones if it wants to supply the later ones.

db48x



^ permalink raw reply	[flat|nested] 23+ messages in thread

* RE: Docs for &optional and &rest arguments together
  2020-12-31 17:28             ` arthur miller
@ 2020-12-31 18:19               ` Drew Adams
  2020-12-31 20:01                 ` arthur miller
  0 siblings, 1 reply; 23+ messages in thread
From: Drew Adams @ 2020-12-31 18:19 UTC (permalink / raw)
  To: arthur miller, tomas, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1846 bytes --]

> I have glanced through though, maybe I am missing it.

 

Don't just glance. Give it the attention that it and your understanding both deserve. If that CL doc didn't help you then I really suggest you sit down, take it slowly, and reread carefully.

 

Both the Elisp doc and the CL doc about this are clear and complete, I think. I suggest with respect that you're maybe just not paying enough attention.

 

Don't be in a hurry. The info is there; just give it a chance - and another read.

 

The CL link is not documentation, it is an essay, entire novel :-). But interestingly, that do not touch on that case either . I have glanced through though, maybe I am missing it. 

 

> > 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:

If someone finds the Elisp doc about lambda lists,
I recommend consulting the Common Lisp doc (CLTL2)
about it.  Common Lisp lambda lists allow more stuff
(&keys, &aux etc.), but for the things that Elisp
has (&optional, &rest) the behavior is the same.

The language in CLTL2 is quite precise.  It too
merits being read carefully, but I think it spells
things out quite clearly.

This is the section about lambda lists, which covers
&optional and &rest:

HYPERLINK "https://urldefense.com/v3/__https:/www.cs.cmu.edu/Groups/AI/html/cltl/clm/node64.html*SECTION00922000000000000000__;Iw!!GqivPVa7Brio!PxyUBvVt3a4Eze6ZtyLlEC6A236XgfttZKnn-7gkT1H6p1FBymyit-C_eQf2-wZH$"https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node64.html#SECTION00922000000000000000

With that, plus the Elisp doc, plus this thread,
I think things will become more clear.  HTH.

[-- Attachment #2: Type: text/html, Size: 5286 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Docs for &optional and &rest arguments together
  2020-12-31 17:08           ` arthur miller
  2020-12-31 17:30             ` Daniel Brooks
@ 2020-12-31 19:40             ` tomas
  1 sibling, 0 replies; 23+ messages in thread
From: tomas @ 2020-12-31 19:40 UTC (permalink / raw)
  To: arthur miller; +Cc: emacs-devel@gnu.org

[-- Attachment #1: Type: text/plain, Size: 987 bytes --]

On Thu, Dec 31, 2020 at 05:08:10PM +0000, arthur miller wrote:
> It Is flera för me hos it work. What I am saying is that docs does not say that we can't omit "optional" c or d when &rest is used. In the examples you are illustrating with, one can't omit say d and write (foo a b  c  e), both c and d are required, so user has to pass explicitly at least nil if not d is provided: (foo a b c nil e)
> 
> Documentation is talking about being able to omit either optional or rest arga, but does not touch on the case when one pass both optional and rest together. In that case optional is not optional any longer.
> 
> I don't understand why is it so difficult to see what I am talking about :-).

I know, it's difficult. It's as difficult for me to see your point.
I'm not being deliberately dense (I take you don't assume that
either). At least not more than I am by nature :)

> Anyway: Happy new year's eve and all best in 2021!

Likewise. All the best!

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* RE: Docs for &optional and &rest arguments together
  2020-12-31 17:30             ` Daniel Brooks
@ 2020-12-31 19:53               ` arthur miller
  0 siblings, 0 replies; 23+ messages in thread
From: arthur miller @ 2020-12-31 19:53 UTC (permalink / raw)
  To: Daniel Brooks; +Cc: tomas@tuxteam.de, emacs-devel@gnu.org

[-- Attachment #1: Type: text/plain, Size: 1160 bytes --]

Jepp. I come on that after I sent first mail and didn't wanted to complicate more later. I don't think docs mention it properly.


-------- Originalmeddelande --------
Från: Daniel Brooks <db48x@db48x.net>
Datum: 2020-12-31 18:30 (GMT+01:00)
Till: arthur miller <arthur.miller@live.com>
Kopia: tomas@tuxteam.de, emacs-devel@gnu.org
Ämne: Re: Docs for &optional and &rest arguments together

arthur miller <arthur.miller@live.com> writes:

> It Is flera för me hos it work. What I am saying is that docs does not
> say that we can't omit "optional" c or d when &rest is used. In the
> examples you are illustrating with, one can't omit say d and write
> (foo a b c e), both c and d are required, so user has to pass
> explicitly at least nil if not d is provided: (foo a b c nil e)

It has the same behavior even when there is no &rest argument. The
caller cannot omit argument c while still supplying argument d without
inserting a nil: (foo a b d) vs (foo a b nil d). Both c and d are
_optional_, because the caller deson't have to supply them. But it does
have to supply the earlier ones if it wants to supply the later ones.

db48x

[-- Attachment #2: Type: text/html, Size: 1843 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* RE: Docs for &optional and &rest arguments together
  2020-12-31 18:19               ` Drew Adams
@ 2020-12-31 20:01                 ` arthur miller
  2020-12-31 20:27                   ` Drew Adams
  0 siblings, 1 reply; 23+ messages in thread
From: arthur miller @ 2020-12-31 20:01 UTC (permalink / raw)
  To: Drew Adams, tomas@tuxteam.de, emacs-devel@gnu.org

[-- Attachment #1: Type: text/plain, Size: 2586 bytes --]

It is New Year Eve Drew. The best lady of all best ladies deserves attention, and I certainly have no need to read references to CL standards and historical mailings etc.

Whatever CL does, who cares, they can do what they want and document what they want. I am pointing at a piece of Elisp documentation which can be better.

But it's not lack of attention, if you actually reflect over what I said, instead of who said it, maybe you will see it too.

Happy New Year, I wish you all best in next year!


-------- Originalmeddelande --------
Från: Drew Adams <drew.adams@oracle.com>
Datum: 2020-12-31 19:19 (GMT+01:00)
Till: arthur miller <arthur.miller@live.com>, tomas@tuxteam.de, emacs-devel@gnu.org
Ämne: RE: Docs for &optional and &rest arguments together

> I have glanced through though, maybe I am missing it.

Don't just glance. Give it the attention that it and your understanding both deserve. If that CL doc didn't help you then I really suggest you sit down, take it slowly, and reread carefully.

Both the Elisp doc and the CL doc about this are clear and complete, I think. I suggest with respect that you're maybe just not paying enough attention.

Don't be in a hurry. The info is there; just give it a chance - and another read.

The CL link is not documentation, it is an essay, entire novel :-). But interestingly, that do not touch on that case either . I have glanced through though, maybe I am missing it.

> > 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:

If someone finds the Elisp doc about lambda lists,
I recommend consulting the Common Lisp doc (CLTL2)
about it.  Common Lisp lambda lists allow more stuff
(&keys, &aux etc.), but for the things that Elisp
has (&optional, &rest) the behavior is the same.

The language in CLTL2 is quite precise.  It too
merits being read carefully, but I think it spells
things out quite clearly.

This is the section about lambda lists, which covers
&optional and &rest:

https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node64.html#SECTION00922000000000000000<https://urldefense.com/v3/__https:/www.cs.cmu.edu/Groups/AI/html/cltl/clm/node64.html*SECTION00922000000000000000__;Iw!!GqivPVa7Brio!PxyUBvVt3a4Eze6ZtyLlEC6A236XgfttZKnn-7gkT1H6p1FBymyit-C_eQf2-wZH$>

With that, plus the Elisp doc, plus this thread,
I think things will become more clear.  HTH.

[-- Attachment #2: Type: text/html, Size: 5586 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* RE: Docs for &optional and &rest arguments together
@ 2020-12-31 20:04 arthur miller
  2020-12-31 20:35 ` tomas
  0 siblings, 1 reply; 23+ messages in thread
From: arthur miller @ 2020-12-31 20:04 UTC (permalink / raw)
  To: tomas@tuxteam.de; +Cc: emacs-devel@gnu.org

[-- Attachment #1: Type: text/plain, Size: 1514 bytes --]

"I know, it's difficult. It's as difficult for me to see your point.
I'm not being deliberately dense (I take you don't assume that
either). At least not more than I am by nature :)"

Of course not! I am thankful for all input.

Thanks! Hope new one will get better. Corona sucked :-)

-------- Originalmeddelande --------
Från: tomas@tuxteam.de
Datum: 2020-12-31 20:41 (GMT+01:00)
Till: arthur miller <arthur.miller@live.com>
Kopia: emacs-devel@gnu.org
Ämne: Re: Docs for &optional and &rest arguments together

On Thu, Dec 31, 2020 at 05:08:10PM +0000, arthur miller wrote:
> It Is flera för me hos it work. What I am saying is that docs does not say that we can't omit "optional" c or d when &rest is used. In the examples you are illustrating with, one can't omit say d and write (foo a b  c  e), both c and d are required, so user has to pass explicitly at least nil if not d is provided: (foo a b c nil e)
>
> Documentation is talking about being able to omit either optional or rest arga, but does not touch on the case when one pass both optional and rest together. In that case optional is not optional any longer.
>
> I don't understand why is it so difficult to see what I am talking about :-).

I know, it's difficult. It's as difficult for me to see your point.
I'm not being deliberately dense (I take you don't assume that
either). At least not more than I am by nature :)

> Anyway: Happy new year's eve and all best in 2021!

Likewise. All the best!

Cheers
- t

[-- Attachment #2: Type: text/html, Size: 2081 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* RE: Docs for &optional and &rest arguments together
  2020-12-31 20:01                 ` arthur miller
@ 2020-12-31 20:27                   ` Drew Adams
  0 siblings, 0 replies; 23+ messages in thread
From: Drew Adams @ 2020-12-31 20:27 UTC (permalink / raw)
  To: arthur miller, tomas, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 2496 bytes --]

I'm not reflecting on who said anything. Just trying to help,

as are others. Happy New Year to you, too.

 

It is New Year Eve Drew. The best lady of all best ladies deserves attention, and I certainly have no need to read references to CL standards and historical mailings etc. 

 

Whatever CL does, who cares, they can do what they want and document what they want. I am pointing at a piece of Elisp documentation which can be better.

 

But it's not lack of attention, if you actually reflect over what I said, instead of who said it, maybe you will see it too. 

 

Happy New Year, I wish you all best in next year!

 

> I have glanced through though, maybe I am missing it.

 

Don't just glance. Give it the attention that it and your understanding both deserve. If that CL doc didn't help you then I really suggest you sit down, take it slowly, and reread carefully.

 

Both the Elisp doc and the CL doc about this are clear and complete, I think. I suggest with respect that you're maybe just not paying enough attention.

 

Don't be in a hurry. The info is there; just give it a chance - and another read.

 

The CL link is not documentation, it is an essay, entire novel :-). But interestingly, that do not touch on that case either . I have glanced through though, maybe I am missing it. 

 

> > 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:

If someone finds the Elisp doc about lambda lists,
I recommend consulting the Common Lisp doc (CLTL2)
about it.  Common Lisp lambda lists allow more stuff
(&keys, &aux etc.), but for the things that Elisp
has (&optional, &rest) the behavior is the same.

The language in CLTL2 is quite precise.  It too
merits being read carefully, but I think it spells
things out quite clearly.

This is the section about lambda lists, which covers
&optional and &rest:

HYPERLINK "https://urldefense.com/v3/__https:/www.cs.cmu.edu/Groups/AI/html/cltl/clm/node64.html*SECTION00922000000000000000__;Iw!!GqivPVa7Brio!PxyUBvVt3a4Eze6ZtyLlEC6A236XgfttZKnn-7gkT1H6p1FBymyit-C_eQf2-wZH$"https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node64.html#SECTION00922000000000000000

With that, plus the Elisp doc, plus this thread,
I think things will become more clear.  HTH.

[-- Attachment #2: Type: text/html, Size: 7308 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Docs for &optional and &rest arguments together
  2020-12-31 20:04 arthur miller
@ 2020-12-31 20:35 ` tomas
  2020-12-31 23:18   ` arthur miller
  0 siblings, 1 reply; 23+ messages in thread
From: tomas @ 2020-12-31 20:35 UTC (permalink / raw)
  To: emacs-devel@gnu.org

[-- Attachment #1: Type: text/plain, Size: 567 bytes --]

On Thu, Dec 31, 2020 at 08:04:55PM +0000, arthur miller wrote:
> "I know, it's difficult. It's as difficult for me to see your point.
> I'm not being deliberately dense (I take you don't assume that
> either). At least not more than I am by nature :)"
> 
> Of course not! I am thankful for all input.

Glad, although I was pretty sure, anyway.

> Thanks! Hope new one will get better. Corona sucked :-)

Hey! You still here? I pictured you having a glass of
something nice with some nice people -- not too many,
mind you. Strange times.

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* RE: Docs for &optional and &rest arguments together
  2020-12-31 20:35 ` tomas
@ 2020-12-31 23:18   ` arthur miller
  0 siblings, 0 replies; 23+ messages in thread
From: arthur miller @ 2020-12-31 23:18 UTC (permalink / raw)
  To: tomas@tuxteam.de, emacs-devel@gnu.org

[-- Attachment #1: Type: text/plain, Size: 979 bytes --]

The best of all best is in 7th month, she is very conservative with taking risks, do we two are at home, having some food and alkofree bubbles. We had video calls with friends and family.

You you have it good as well!


-------- Originalmeddelande --------
Från: tomas@tuxteam.de
Datum: 2020-12-31 21:35 (GMT+01:00)
Till: emacs-devel@gnu.org
Ämne: Re: Docs for &optional and &rest arguments together

On Thu, Dec 31, 2020 at 08:04:55PM +0000, arthur miller wrote:
> "I know, it's difficult. It's as difficult for me to see your point.
> I'm not being deliberately dense (I take you don't assume that
> either). At least not more than I am by nature :)"
>
> Of course not! I am thankful for all input.

Glad, although I was pretty sure, anyway.

> Thanks! Hope new one will get better. Corona sucked :-)

Hey! You still here? I pictured you having a glass of
something nice with some nice people -- not too many,
mind you. Strange times.

Cheers
 - t

[-- Attachment #2: Type: text/html, Size: 1697 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Docs for &optional and &rest arguments together
  2020-12-29 15:10 ` Adam Porter
  2020-12-29 17:06   ` arthur miller
@ 2021-01-01 14:33   ` Arthur Miller
  1 sibling, 0 replies; 23+ messages in thread
From: Arthur Miller @ 2021-01-01 14:33 UTC (permalink / raw)
  To: Adam Porter; +Cc: emacs-devel

Adam Porter <adam@alphapapa.net> writes:

> This doesn't exactly answer your question, but here's an alternative you
> might be interested in: I wrote a similar macro a while back, and I
> tried to follow CL-style arguments by using a list of options.
>
> https://github.com/alphapapa/elexandria/blob/83a1b08d0711fdce07a5b33525535cc3a457c6ee/elexandria.el#L105
>
> Here's the source code:
>
> (cl-defmacro with-file-buffer (path options &body body)
>   "Insert contents of file at PATH into a temp buffer, and evaluate and return the value of BODY in it.
> OPTIONS is a plist accepting the following options:
>
> `:must-exist': If non-nil, raise an error if no file exists at
> PATH.
>
> `:write': If non-nil, write the contents of the buffer to file at
> PATH after evaluating BODY.
>
> `:overwrite': If nil (or unset), raise an error instead of
> overwriting an existing file at PATH.  If `ask', ask for
> confirmation before overwriting an existing file.  If t,
> overwrite a file at PATH unconditionally.
>
> `:append': Passed to function `write-region', which see.
>
> `:visit':  Passed to function `write-region', which see."
>   (declare (indent 2))
>   `(with-temp-buffer
>      (if (file-readable-p ,path)
>          (insert-file-contents ,path)
>        (when ,(plist-get options :must-exist)
>          (error "File not readable: %s" ,path)))
>      (prog1
>          (progn
>            ,@body)
>        ,(when (plist-get options :write)
>           `(write-region nil nil path
>                          ,(plist-get options :append)
>                          ,(plist-get options :visit)
>                          ,(pcase-exhaustive (plist-get options :overwrite)
>                             ('nil ''excl)
>                             ((or 'ask ''ask) ''ask)
>                             ('t nil)))))))
Indeed, looks nice! thanks.



^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2021-01-01 14:33 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-29 13:26 Docs for &optional and &rest arguments together Arthur Miller
2020-12-29 15:10 ` Adam Porter
2020-12-29 17:06   ` arthur miller
2021-01-01 14:33   ` Arthur Miller
2020-12-30  3:12 ` Lars Ingebrigtsen
2020-12-30 12:19   ` Arthur Miller
2020-12-30 12:54     ` Yuri Khan
2020-12-31  4:43     ` Lars Ingebrigtsen
2020-12-31  7:55       ` arthur miller
2020-12-31 11:26         ` tomas
2020-12-31 16:45           ` Drew Adams
2020-12-31 17:04             ` Drew Adams
2020-12-31 17:28             ` arthur miller
2020-12-31 18:19               ` Drew Adams
2020-12-31 20:01                 ` arthur miller
2020-12-31 20:27                   ` Drew Adams
2020-12-31 17:08           ` arthur miller
2020-12-31 17:30             ` Daniel Brooks
2020-12-31 19:53               ` arthur miller
2020-12-31 19:40             ` tomas
  -- strict thread matches above, loose matches on Subject: below --
2020-12-31 20:04 arthur miller
2020-12-31 20:35 ` tomas
2020-12-31 23:18   ` arthur miller

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.