unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Rationale behind conversion of a nil prefix arg to numeric 1
@ 2016-09-04 12:23 Florian v. Savigny
  2016-09-04 14:23 ` Eli Zaretskii
  2016-09-15 12:47 ` Thien-Thi Nguyen
  0 siblings, 2 replies; 31+ messages in thread
From: Florian v. Savigny @ 2016-09-04 12:23 UTC (permalink / raw)
  To: help-gnu-emacs



Hi there,

I've written one or two functions whose invocation I modeled on Unix
file permission bits (where a single digit is always unambiguously
either 1, 2 and 4 or some sum of them; thus, possible values are 1, 2,
3 (1 + 2), 4, 5 (1 + 4), 6 (2 + 4) and 7 (1 + 2 + 4)) because I felt
it was quite a nifty way of passing a command zero, one, two or three
"flags" at once via an optional prefix argument. (Apart from the fact
that it's quite easy to forget which number means which flag.)

Naively, I used the numeric conversion of the prefix arg, i.e.

   (interactive "p")

which passes the prefix arg converted to a number. However, if I call
the function with no prefix argument, which is, expectedly, nil in raw
form, it converts this to the number 1. (This is what
`prefix-numeric-value' does, as explained in the docstring.)

While I understand that this is how it is done, I am quite puzzled
about the logic behind this. It would seem intuitive to me to convert
nil to either the number 0 or, again, nil, but never to the number
1. And practically, converting nil to 1 has the consequence that
calling the command with no prefix arg:

   M-x command

is exactly the same as calling it with a prefix arg of 1:

   C-u 1 M-x command

because the prefix arg converted to a number is 1 in both cases, which
reduces the number of possibilities of calling the command by one.

I can circumvent this (and get the behaviour that I would expect) by
writing the function with

   (if current-prefix-arg (prefix-numeric-value current-prefix-arg))

in an explicit interactive list, but I am still wondering about the
rationale of representing nil as the number one. Does this make sense,
or is it useful, in some way?


Thanks for any enlightenment!

Florian




-- 

Florian von Savigny
Melanchthonstr. 41
33615 Bielefeld



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

end of thread, other threads:[~2016-09-15 12:47 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-04 12:23 Rationale behind conversion of a nil prefix arg to numeric 1 Florian v. Savigny
2016-09-04 14:23 ` Eli Zaretskii
2016-09-04 17:11   ` Andreas Röhler
2016-09-04 18:33     ` Eli Zaretskii
2016-09-05  7:16       ` Andreas Röhler
2016-09-05 14:56         ` Eli Zaretskii
2016-09-05 15:22           ` Kaushal Modi
2016-09-05 16:32             ` Drew Adams
2016-09-05 18:41             ` Andreas Röhler
2016-09-05 19:02               ` Eli Zaretskii
2016-09-06  7:10                 ` tomas
2016-09-06  9:45                   ` Florian v. Savigny
2016-09-06 10:27                     ` tomas
2016-09-06 11:27                     ` Andreas Röhler
2016-09-06 13:27                       ` Florian v. Savigny
2016-09-06 15:22                         ` Drew Adams
2016-09-06 14:20                       ` Kaushal Modi
2016-09-06 16:44                         ` Andreas Röhler
2016-09-06 16:41                           ` Kaushal Modi
2016-09-07 23:11                         ` Charles Millar
2016-09-08 13:10                           ` Kaushal Modi
2016-09-08 14:42                             ` Charles Millar
2016-09-08 15:40                           ` Drew Adams
2016-09-06  7:22                 ` Andreas Röhler
2016-09-05 17:04         ` Drew Adams
2016-09-05 21:39           ` Florian v. Savigny
     [not found]           ` <<877faqvxfp.fsf@bertrandrussell.Speedport_W_723V_1_40_000>
2016-09-05 23:32             ` Drew Adams
2016-09-06  3:45               ` B.V. Raghav
2016-09-04 22:53   ` Florian v. Savigny
     [not found]   ` <<87d1kjjmys.fsf@bertrandrussell.Speedport_W_723V_1_40_000>
2016-09-05  0:52     ` Drew Adams
2016-09-15 12:47 ` Thien-Thi Nguyen

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).