unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Jean Louis <bugs@gnu.support>
Cc: "tomas@tuxteam.de" <tomas@tuxteam.de>,
	"help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: RE: [External] : Re: How to make M-x TAB not work on (interactive) declaration?
Date: Wed, 18 Jan 2023 20:36:56 +0000	[thread overview]
Message-ID: <SJ0PR10MB5488A23773107476AD48855AF3C79@SJ0PR10MB5488.namprd10.prod.outlook.com> (raw)
In-Reply-To: <Y8gDDGHW9LKTYyZl@protected.localdomain>

> > Imagine that functions such as + and * accept a
> > single _list_ argument, _instead of_ a variable
> > number (including zero) of arguments.
> >
> > Can you see that such a function is useful?
> 
> No.
> (* 2) ➜ 2
> I do not see how it is useful, except for some funny stuff.

Are you not reading what I write?  "single _list_
argument".  I'm trying to help you understand the
use of variable-arity functions.

Most languages pass an explicit list of values
instead of a variable number of args, to be able
to act on multiple values.

Folks who find variable arity odd can usually
understand that it's essentially what they're
already used to in the form of passing a list of
values.  That isn't unusual; variable arity is
unusual.  That's why I spoke about instead passing
a _list_ of values.

> > Can you see that it's general - and that you can
> > even pass it the empty list or a singleton list?
> 
> I can't pass list in this way (* nil) and I do not
> know how you wish to pass it. 

See the code I provided.  Passing a list of values
to a unary `foo':

(foo '(3 6 9))
(foo '(2))
(foo ())

Passing multiple values to a variable-arity `foo':

(foo 3 6 9)
(foo 2)
(foo)

Those are different functions.  The idea's similar.
That's all.  The point was to show you how other
languages accomplish the same thing (applying a
function to an arbitrary number of values) - they
use a list.

> > OK, let's look into that...
> > Such functions would cdr down the list argument
> > adding/multiplying the next number from the list
> > by the sum/product accumulated so far.
> 
> Was it so maybe in some early Lisp?

Don't know and don't care.  It's common in languages
where functions have typed signatures etc.  That's
what you have and do in Haskell, for instance: pass
a list, if you want to act on an arbitrary number of
values.

> > It's far simpler and more general for them to
> > initialize at the top level: _before_ dealing
> > with the first arg.  The obvious init-value
> > choice for + is zero, and the obvious choice
> > for * is one.  That's all that's going on.
> >
> > Or, what initial values would you have such
> > functions start with, for their accumulating
> > sum/product?  Clearly you'd want + to start
> > with 0 and * to start with 1, no?
> 
> If dividion (/ 10 2) is initialized with 10, then 
> (* A B) can be initialized by A. I expect error.

No idea what wavelength you're on here; sorry.

I was talking about initializing a function that
accumulates - such as Elisp's +.

> Without practical use I can only tell it is capricious decision.

Without using it or understanding it you can
continue to think so, I suppose.

If you want to add four numbers without taking
advantage of (+ 3 6 2 8), then just do so:
(+ 3 (+ 6 (+ 2 8))) or (+ (+ (+ 3 6) 2) 8) or...
Go for it - Lisp won't mind.

> Maybe we can tell it this way:
> If there is any Emacs Lisp program which does not use (*) or (* a)
> anywhere but which would raise error if we re-define function
> to require 2 arguments -- then there must be some use of it.

How about + or * with more than 2 args?  Do you
think allowing that is also useless imagination,
a capricious decision, madness imposed by useless
mathematicians?

If you can see how it can be useful to use + and
* with more than 2 args, then the case for passing
an arbitrary number of args is made.  If your only
problem now is seeing why allowing such generality
should _also_ allow (+ 3) and (+) then I think
we've made some progress.

Submit an enhancement request if you like: Don't
allow + and * (and the like) to accept less than
two args.  See how well that request goes over.

> Otherwise I get idea it was just pecular decision.

_Lisp_ is a peculiar decision all 'round.  Get over
it - that's my suggestion.  Better is to understand
it and put your own thinking in question first, but
if you can't, or don't want to, do that then just
get over it.  I showed you how to code your own
addition function that accepts two or more args.
And it's just as easy to code your own that requires
exactly two.  Roll your own and be happy ever after.

> > Now, what value would you have + return for a
> > singleton list - e.g., (42)?  What value would
> > you have it return for the empty list, ()?  I
> > think you'd want (+ '(42)) to return 42 and
> > (+ ()) to return 0, no?  If so, why?  (That's
> > the question others have been answering by
> > mentioning additive/multiplicative identities.)
> 
> Just that (+ nil) does not really work. Example 
> cannot be shown practically.

You're really not reading well.  That was in the
context of an addition function that accepts a
single list arg instead of multiple args.  It was
for my apparently unsuccessful attempt to get you
past the "peculiarity" of variable arity.

> It is for adding numbers, not for adding numbers in a list.

Q:  How does one add multiple numbers in a single
    function call?
A1: Pass them in a list argument.
A2: Pass them as multiple arguments.

A2 is possible only in languages that allow
variable arity.  A1, or fiddling with partial
application, is what most languages use.

> Which Emacs Lisp program will break if we demand
> 2 elements for *, - and + ?

Any that uses more than 2 args.  There're thousands
such uses.  Your focusing on the nullary and single
arg cases is _______.  The main use of the variable
arity of these functions is for _2 or more_ values.

The uses of zero or one value are typically for a
base case of a recursion or the limiting case of an
iteration.  Yes, such cases could instead use code
that's a bit more complicated, bottoming out when
getting down to 2 args.  But who would want to need
such bother?  (You, I guess?  Check back later.)
 
> By answering that question we can see where it is usable.

We see where it's usable.  You haven't yet, but I'm
certain you will at some point.

> > Now consider functions such as min and max.
> >
> > There's no minimum or maximum number, so they
> > clearly can't be called with _no_ args.  But
> > they can be called with a _single_ arg, and,
> > like + and *, their definitions return that
> > number - it's _not compared_ with any other
> > number, so how can we say it's the smallest
> > or largest?  It's the smallest/largest of the
> > numbers provided - no comparison is needed.
> 
> (min 1 2) ➜ 1
> (max 2 3) ➜ 3

??  You're really not reading, are you?

> Or do you think it was just made because it has to be made that way,
> and that is authoritative opinion of mathematicians, but we have
> absolutely no use of it in Lisp?

Do I think that?  No.  Does anyone?

> If it is about errors, why then we allow / to have 
> error but * not to have error?

Your questions about this have been answered over
and over, by others.  Division and subtraction
are not the same as multiplication and addition.

> For me is not logical this: (apply '* '()) ➜ 1 because I want error to
> tell me that I did not provide arguments for multiplication.

I gave you code to do that.

> So, I tend to conclude that reason is peculiar decision of some
> authors who wanted to make it look more "mathematical" (just because)
> even though there is no practical use of it.
> 
> And I still hope to find the true background of it.

It doesn't sound like you do.

  reply	other threads:[~2023-01-18 20:36 UTC|newest]

Thread overview: 149+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-07 20:53 How to make M-x TAB not work on (interactive) declaration? Jean Louis
2023-01-07 21:11 ` Ruijie Yu via Users list for the GNU Emacs text editor
2023-01-07 23:40   ` Jean Louis
2023-01-08  6:06 ` Eli Zaretskii
2023-01-08  6:19   ` Emanuel Berg
2023-01-09  4:49     ` Jean Louis
2023-01-09  6:26       ` algorithmic Lisp language (was: Re: How to make M-x TAB not work on (interactive) declaration?) Emanuel Berg
2023-01-09 19:30         ` Jean Louis
2023-01-09 19:32         ` Jean Louis
2023-01-08  6:21   ` How to make M-x TAB not work on (interactive) declaration? Jean Louis
2023-01-08  6:32     ` Emanuel Berg
2023-01-08 10:38     ` Eli Zaretskii
2023-01-08  8:34 ` Tassilo Horn
2023-01-08 11:01   ` Eli Zaretskii
2023-01-09 13:29     ` Tassilo Horn
2023-01-08 21:35   ` Jean Louis
2023-01-08 22:35     ` [External] : " Drew Adams
2023-01-09  0:24       ` Emanuel Berg
2023-01-09 19:47         ` Jean Louis
2023-01-10 23:28           ` Emanuel Berg
2023-01-13  6:21             ` (*)->1 Jean Louis
2023-01-14 12:03               ` (*)->1 Michael Heerdegen
2023-01-14 12:33                 ` (*)->1 Michael Heerdegen
2023-01-15 20:18           ` [External] : Re: How to make M-x TAB not work on (interactive) declaration? Rudolf Adamkovič
2023-01-15 20:57             ` Jean Louis
2023-01-15 22:33               ` Drew Adams
2023-01-15 23:10                 ` Emanuel Berg
2023-01-16 15:28                 ` Jean Louis
2023-01-16 17:07                   ` Drew Adams
2023-01-16 18:25                     ` Jean Louis
2023-01-17  2:20                       ` Drew Adams
2023-01-17  5:28                         ` tomas
2023-01-17 22:20                           ` Drew Adams
2023-01-18  5:14                             ` tomas
2023-01-18  5:26                               ` Emanuel Berg
2023-01-19 11:38                                 ` tomas
2023-01-19 11:51                                   ` Emanuel Berg
2023-01-21 14:05                                     ` tomas
2023-01-23 10:14                                       ` Robert Pluim
2023-01-23 16:44                                       ` Michael Heerdegen
2023-01-23 19:28                                         ` tomas
2023-01-18 17:27                               ` Drew Adams
2023-01-18 17:32                                 ` tomas
2023-01-18 14:32                             ` Jean Louis
2023-01-18 20:36                               ` Drew Adams [this message]
2023-01-19  9:05                                 ` (*) -> 1 Jean Louis
2023-01-19  9:41                                   ` Yuri Khan
2023-01-19 12:52                                   ` Anders Munch
2023-01-17  5:35                         ` [External] : Re: How to make M-x TAB not work on (interactive) declaration? Jean Louis
2023-01-17 15:59                           ` Yuri Khan
2023-01-17 16:42                             ` Jean Louis
2023-01-17 16:05                           ` Michael Heerdegen
2023-01-17 16:17                             ` Yuri Khan
2023-01-17 16:25                             ` tomas
2023-01-17 16:55                             ` (*) -> 1 Jean Louis
2023-01-17 17:52                               ` Michael Heerdegen
2023-01-17 18:11                                 ` Óscar Fuentes
2023-01-17 18:40                                   ` Jean Louis
2023-01-17 19:04                                     ` Óscar Fuentes
2023-01-18 13:15                                       ` Jean Louis
2023-01-18 14:37                                         ` Óscar Fuentes
2023-01-18 18:17                                         ` [External] : " Drew Adams
2023-01-17 19:35                                     ` Michael Heerdegen
2023-01-17 21:12                                   ` Michael Heerdegen
2023-01-17 22:01                                     ` Óscar Fuentes
2023-01-17 23:38                                       ` Michael Heerdegen
2023-01-18  7:50                                         ` Óscar Fuentes
2023-01-18  8:37                                           ` tomas
2023-01-18 12:46                                             ` Óscar Fuentes
2023-01-18 13:44                                               ` Michael Heerdegen
2023-01-18 14:07                                                 ` Óscar Fuentes
2023-01-18 16:19                                                   ` Andreas Eder
2023-01-18 17:14                                                     ` Óscar Fuentes
2023-01-17 18:18                                 ` Jean Louis
2023-01-17 11:52                         ` [External] : Re: How to make M-x TAB not work on (interactive) declaration? Michael Heerdegen
2023-01-15 21:08             ` Jean Louis
2023-01-16  5:02               ` Emanuel Berg
2023-01-16  5:38               ` tomas
2023-01-16 10:10                 ` Jean Louis
2023-01-16 10:41                   ` Yuri Khan
2023-01-16 15:26                     ` Jean Louis
2023-01-17  4:06                 ` Emanuel Berg
2023-01-17 14:00                   ` tomas
2023-01-17 22:43                     ` Emanuel Berg
2023-01-17 16:25                 ` Nick Dokos
2023-01-17 17:19                   ` Jean Louis
2023-02-11  4:38                     ` Ruijie Yu via Users list for the GNU Emacs text editor
2023-02-11 10:54                       ` Jean Louis
2023-01-17 17:41                   ` Nick Dokos
2023-01-16  7:55               ` Yuri Khan
2023-01-16 10:16                 ` Jean Louis
2023-01-16 10:37                   ` Yuri Khan
2023-01-16 15:35                     ` Jean Louis
2023-01-16 15:59                       ` Yuri Khan
2023-01-16 16:14                         ` Jean Louis
2023-01-16 16:47                           ` tomas
2023-01-16 17:07                           ` Drew Adams
2023-01-16 18:41                             ` Jean Louis
2023-01-16 10:51                   ` Anders Munch
2023-01-16 15:38                     ` Jean Louis
2023-01-16 17:40                       ` Andreas Eder
2023-01-16 18:17                         ` tomas
2023-01-16 18:55                           ` Jean Louis
2023-01-16 19:14                             ` tomas
2023-01-16 18:46                         ` Jean Louis
2023-01-17  2:37                           ` Eduardo Ochs
2023-01-17  5:46                             ` (*) -> 1 Jean Louis
2023-01-17 15:56                               ` Michael Heerdegen
2023-01-17 16:29                                 ` Jean Louis
2023-01-17 16:43                                   ` tomas
2023-01-17 17:25                                     ` Jean Louis
2023-01-17 19:11                                       ` Nick Dokos
2023-01-17 17:17                                   ` Michael Heerdegen
2023-01-17 17:26                                     ` Jean Louis
2023-01-17 18:46                                       ` Michael Heerdegen
2023-01-17 18:51                                         ` Jean Louis
2023-01-17 18:04                                     ` Jean Louis
2023-01-17 18:28                                       ` Eduardo Ochs
2023-01-17 19:18                                       ` Michael Heerdegen
2023-01-18 12:27                                         ` Jean Louis
2023-01-18 13:37                                           ` Michael Heerdegen
2023-01-19  8:20                                             ` Jean Louis
2023-01-19 10:06                                               ` Tassilo Horn
2023-01-19 13:43                                               ` Michael Heerdegen
2023-01-19 14:42                                                 ` Jean Louis
2023-01-19 15:27                                                   ` tomas
2023-01-18 13:57                                           ` Óscar Fuentes
2023-01-19  8:32                                             ` Jean Louis
2023-01-19 16:51                                               ` Óscar Fuentes
2023-01-20  8:01                                                 ` Jean Louis
2023-01-18 14:25                                           ` Michael Heerdegen
2023-01-19  8:34                                             ` Jean Louis
2023-01-19 13:54                                               ` Michael Heerdegen
2023-01-19 14:54                                                 ` Jean Louis
2023-01-19 15:19                                                   ` Tassilo Horn
2023-01-19 15:46                                                   ` Michael Heerdegen
2023-01-19 17:38                                                   ` Dr Rainer Woitok
2023-01-20  7:31                                                     ` Jean Louis
2023-01-20 11:49                                                       ` Dr Rainer Woitok
2023-01-19 17:44                                                 ` [External] : " Drew Adams
2023-01-19 21:29                                                   ` Michael Heerdegen
2023-01-20  7:40                                                     ` Jean Louis
2023-01-20  8:47                                                       ` Emanuel Berg
2023-01-18  9:02                                 ` Anders Munch
2023-01-18 10:49                                   ` Michael Heerdegen
2023-01-18 11:10                                     ` Emanuel Berg
2023-01-18 12:48                                   ` Eli Zaretskii
2023-01-18 14:29                                     ` Michael Heerdegen
     [not found]                           ` <87k01lica7.fsf@eder.anydns.info>
2023-01-17 16:04                             ` Jean Louis

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=SJ0PR10MB5488A23773107476AD48855AF3C79@SJ0PR10MB5488.namprd10.prod.outlook.com \
    --to=drew.adams@oracle.com \
    --cc=bugs@gnu.support \
    --cc=help-gnu-emacs@gnu.org \
    --cc=tomas@tuxteam.de \
    /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.
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).