[Top][All Lists]

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

bug#31715: cl-incf and cl-decf error out when passed a nil-valued variab

From: Noam Postavsky
Subject: bug#31715: cl-incf and cl-decf error out when passed a nil-valued variable as 'offset'
Date: Tue, 05 Jun 2018 19:26:51 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

Clément Pit-Claudel <address@hidden> writes:

> I'm not sure what to make of the result with SBCL and CLisp, since
> (incf x nil) also fails in both of them (whereas it works for us,
> since we can't distinguish nil and unspecified).

Oh, huh, I didn't think to check that case.  Maybe we should just change
cl-incf to disintguish between nil and unspecified then.

(defmacro cl-incf (place &rest args)
  "Increment PLACE by X (1 by default).
PLACE may be a symbol, or any generalized variable allowed by `setf'.
The return value is the incremented value of PLACE.

\(fn PLACE &optional X)"
  (declare (debug (place &optional form)))
  (let* ((got-x (= (length args) 1))
         (x (car args)))
    (if (symbolp place)
        (list 'setq place (if got-x (list '+ place x) (list '1+ place)))
      (list 'cl-callf '+ place (if got-x x 1)))))

>>> In the rest of Emacs there are lots of other examples.  Many of them
>>> (for example semantic-find-tags-by-name or calendar-increment-month)
>>> seem to work when passed a nil-valued variable, but many others behave
>>> like cl-incf (for example gnus-summary-article-score).
>> I don't think those are great examples of macros to emulate.
> Agreed, I was just collecting other examples, both in support and against my 
> point.

Yeah, I just meant we can't really use those examples either to support
or argue against your point.

reply via email to

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