GNU bug report logs - #31715
cl-incf and cl-decf error out when passed a nil-valued variable as 'offset'

Previous Next

Package: emacs;

Reported by: Clément Pit-Claudel <clement.pitclaudel <at> live.com>

Date: Mon, 4 Jun 2018 20:08:01 UTC

Severity: minor

Fixed in version 29.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


Message #8 received at 31715 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Clément Pit-Claudel <clement.pitclaudel <at> live.com>
Cc: 31715 <at> debbugs.gnu.org
Subject: Re: bug#31715: cl-incf and cl-decf error out when passed a nil-valued
 variable as 'offset'
Date: Mon, 04 Jun 2018 18:58:01 -0400
Clément Pit-Claudel <clement.pitclaudel <at> live.com> writes:

> The following works:
>   (let ((x 1)) (cl-incf x nil))
>
> … but following raises "setq: Wrong type argument: number-or-marker-p, nil":
>   (let ((x 1) (y nil)) (cl-incf x y))
>
> … yet the docs say this, which suggests that both should work:
>   (cl-incf PLACE &optional X)
>   Increment PLACE by X (1 by default).

X is an optional macro parameter, so the "optionalness" applies at
compile time.

> The issue comes from the expansion of cl-incf:
>
>     (defmacro cl-incf (place &optional x) …
>       (if (symbolp place)
>           (list 'setq place (if x (list '+ place x) (list '1+ place)))
>         (list 'cl-callf '+ place (or x 1))))
>
> Shouldn't that `if x' check be quoted?  Same for the second branch of the if (shouldn't the `(or x 1)' part be quoted, too?)

I think that would approximately double the cost of cl-incf in the
simple case.  And since you would expect cl-incf to be used in loops a
lot, that seems like a bad idea.




This bug report was last modified 3 years and 34 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.