From: Drew Adams <drew.adams@oracle.com>
To: "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: Tue, 17 Jan 2023 22:20:47 +0000 [thread overview]
Message-ID: <CO6PR10MB547340CEDCDACAF11FF2BA94F3C69@CO6PR10MB5473.namprd10.prod.outlook.com> (raw)
In-Reply-To: <Y8YyG9cMb7UrgPXJ@tuxteam.de>
> > > Any number means also no argument? To me that is not clear.
> >
> > That's why I pointed out that _zero is a number_.
>
> Those are big words :-)
>
> Minus one is also a number, but we'd be hard pressed to come
> up with a function taking minus one arguments. Three-quarters,
> the square root of two and pi are numbers. Arguably, "the"
> Chaitin constant [1] (actually there are many of them)is also
> a number.
>
> I think the manual wants to say "natural number" and just
> says "number", but that's OK, because it is directed at humans,
> and we humans are usually better at disambiguating given a
> context than at staying awake in front of long and boring texts.
>
> Arguably, "zero or more" might be clearer here, but I don't
> know (after all, the square root of two is bigger than zero,
> too).
1. I said "More precisely: zero or more" in my
second reply to this thread:
Not to belabor this... but perhaps you're missing
understanding _zero as a number_, in "number of
arguments". More precisely: zero or more args.
2. There's no need to say anything more than
"any number of arguments" - the number of args
has to be zero or more, because we allow nullary
functions.
3. If someone has a hard time with functions of
variable arity, then just pretend you have this
equivalent: replace each Lisp function that
accepts a variable number of args with a function
that accepts a _list arg_ (whose elements are
what would be the variable number of args) in
their place.
Most functional, logic, etc. languages just use
a list arg - same difference. There's nothing
magic about variable-arity functions - they're
really just functions that accept a list arg.
________________________
Jean Louis:
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?
Can you see that it's general - and that you
can even pass it the empty list or a singleton
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.
The functions would have to start with _some_
initial value for the accumulated sum/product.
If they use simple recursion, applying the same
operation at each level (add/multiply next number
by accumulated sum/product), they need to start
by initializing the sum/product.
For them to seemingly start with the first number
in the list they'd need to initialize instead
within the general operation performed at each
level, which would require extra fiddling, to
(1) test whether it's the first time through
and if so then (2) initialize.
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?
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.)
Now, since Lisp allows variable-arity functions,
there's no reason to insist that an _explicit
list_ be passed, instead of just the elements
(numbers, here) that would be in that list.
That's the shortcut that Lisp takes: don't
bother to wrap the numbers in a list.
(Creating lists is costly: consing, and then
later garbage-collecting all those conses.
Using an explicit list gains us nothing.)
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.
And as for doc, note that the doc tells us
that there _must be at least one_ arg. Well,
it doesn't tell you this in so many words (it
could; perhaps it should). But the function
signature is part of its doc, and `C-h f max'
tells us:
___
max is a built-in function in ‘C source code’.
(max NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS)
Return largest of all the arguments (which must be numbers or markers).
The value is always a number; markers are converted to numbers.
___
"NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS"
tells you the function requires an argument,
and it accepts more than one arg. If it
didn't require at least one arg then the
signature would be "&rest NUMBERS-OR-MARKERS ".
___
If you don't like Lisp's predefined +, *, etc.
it's simple enough to roll your own, and make
them _require at least 2_ arguments. E.g.:
(defmacro my-plus (n1 n2 &rest ns)
"..."
`(+ ,n1 ,n2 ,@ns))
And if you prefer to handle the identity
element explicitly, here's how to define a
`plus' function that does what + does, using
a more general, higher-order function, called
`reduce', aka `foldr':
(defun foldr (f init xs)
(if (null xs)
init
(funcall f (car xs) (foldr f init (cdr xs)))))
(defun plus (&rest ns)
(foldr #'my-plus 0 ns))
That is, Elisp's + (named `plus' here), could
be defined based on your `my-plus', using
`foldr', passing it 0 (additive identity) as
the initial element, argument INIT.
`plus' is just (1) your `my-plus', which
_requires two numbers_, (2) _folded_ into an
_explicit list_ of numbers - a list that
_can_ be empty or a singleton.
Elisp's + acts the same as that `plus', but
it's coded in C, and it creates no useless
intermediate list (to be garbage-collected).
________________________
Back to Tomas's mail...
> Now mathematicians don't agree on whether
> zero is a natural number.
That's just saying that they define "natural
number" differently.
> The faculty I studied in started counting from zero,
> but I've seen faculties which count from one. I once asked
> a friend of mine teaching at one uni, and he told me faculties
> having a strong mathematical logic department tended to start
> with zero.
This is a red herring here. "Natural", "whole",
"countable"/"counting" numbers are just names.
Different definitions are sometimes given to the
names, yes.
When talking about the number of args a Lisp
function accepts, or the number of elements a list
can have, the counting is clearly zero-based: a
function can be nullary, and a list can be empty:
(). (Likewise, a string or a vector.)
> So zero may be a number or not, at least if you read "number"
> as "natural number", and you ask a mathematician :)
And if you read "number" as "triangular number"
then it's not. This is really irrelevant here.
Clearly, if you read "number" as some set that
_excludes zero_, then zero doesn't belong to it.
Lisp functions can be nullary: take no arguments.
How many arguments? Zero. What's the _number_
of arguments a nullary function takes? Zero.
next prev parent reply other threads:[~2023-01-17 22:20 UTC|newest]
Thread overview: 167+ 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 [this message]
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
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-19 8:37 ` Jean Louis
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-20 7:05 ` Jean Louis
2023-01-20 8:52 ` Tassilo Horn
2023-01-20 12:46 ` Jean Louis
2023-01-20 13:02 ` Tassilo Horn
2023-01-20 16:06 ` Jean Louis
2023-01-21 8:19 ` Tassilo Horn
2023-01-22 4:30 ` Emanuel Berg
2023-01-22 6:55 ` Jean Louis
2023-01-22 10:56 ` Emanuel Berg
2023-01-23 3:40 ` [External] : " Drew Adams
2023-01-22 14:34 ` Akib Azmain Turja
2023-01-23 2:23 ` Emanuel Berg
2023-01-23 5:37 ` Jean Louis
2023-01-23 5:55 ` Jean Louis
2023-01-24 2:33 ` Emanuel Berg
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 14:54 ` Jean Louis
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-20 7:33 ` Jean Louis
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CO6PR10MB547340CEDCDACAF11FF2BA94F3C69@CO6PR10MB5473.namprd10.prod.outlook.com \
--to=drew.adams@oracle.com \
--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.
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.