help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Rationale behind conversion of a nil prefix arg to numeric 1


From: Andreas Röhler
Subject: Re: Rationale behind conversion of a nil prefix arg to numeric 1
Date: Mon, 5 Sep 2016 09:16:00 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:45.0) Gecko/20100101 Icedove/45.2.0



On 04.09.2016 20:33, Eli Zaretskii wrote:
From: Andreas Röhler <address@hidden>
Date: Sun, 4 Sep 2016 19:11:31 +0200

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?
Yes.  Most commands use the argument as a repeat count, so having it
default to one makes perfect sense.

There a difference between "p" sending 1 and nil - which is the result
from non-interactive use.
"p" is documented as the _numeric_ value of the argument.  So it
obviously cannot yield nil.

The ideosyncrasy: it yields the same value for arg = 1 as if no arg were given:

(defun foo (&optional arg)
  (interactive "p")
  (message "My ARG: %s" arg)
  (message "Value of arg: %s" (prefix-numeric-value arg)))


;; called without ARG
(foo)
     ==> "My ARG: nil"
     ==> "Value of arg: 1"

;; called without ARG 1
(foo 1)

     ==> "My ARG: 1"
     ==> "Value of arg: 1"


Regardless of its purpose - such coding style should not be encouraged.

It would be easy and consistent to write

(or arg (setq arg 1))






reply via email to

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