emacs-devel
[Top][All Lists]
Advanced

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

Re: master a6b5985: Avoid duplicated character classes in rx


From: Stefan Monnier
Subject: Re: master a6b5985: Avoid duplicated character classes in rx
Date: Tue, 03 Dec 2019 10:26:51 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

>>              ((and (symbolp arg)
>>                    (let ((class (cdr (assq arg rx--char-classes))))
>> -                    (and class (push class classes)))))
>> +                    (and class
>> +                         (or (memq class classes)
>> +                             (push class classes))))))
>
> This (which is a branch of a `cond') relies in the fact that (push ELEMENT
> LISTNAME)
> returns the new LISTNAME.
>
> Which isn't really documented. It's sort-of-documented because push's
> docstring
> says that it is "morally equivalent to (setf place (cons newelt place)",
> and the
> elisp manual says that it is "equivalent to (setq ...)" or that it "does the
> equivalent of (setf ...)".
>
> Shouldn't we say it in its docstring?

I'd rather fix the code not to rely on the return value.
E.g.

                 ((and (symbolp arg)
                       (let ((class (cdr (assq arg rx--char-classes))))
    -                    (and class (push class classes)))))
    +                    (and class
    +                         (progn (cl-pushnew class classes) t))))


-- Stefan




reply via email to

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