emacs-devel
[Top][All Lists]
Advanced

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

Re: lengths and other stuff


From: Daniel Brooks
Subject: Re: lengths and other stuff
Date: Sun, 27 Dec 2020 15:32:23 -0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> A quick check does show that they were moved to subr.el from cl-lib.el
>> just three years ago. Nearly four now. Also that they were called
>> cl-cadar and so on. Weird.
>
> That's because they suck.  They feel to me like programming in
> assembler.  You're usually much better off using `nth` or `pcase` or
> `cl-destructuring-bind`, ...

Definitely. But a common enough pattern is to use list structure as if
it were a struct, with constructors and accessor methods that hide the
implementation details:

    (defun make-complex (x y) (cons 'complex (cons x y))
    (defun complex-x (c) (and (eq 'complex (car c)) (cadr c)))
    (defun complex-y (c) (and (eq 'complex (car c)) (cddr c)))

That is, the c*r methods are good and useful predefined accessors, but
you give them appropriate names so that you're not using them
directly. That way you don't make your users remember how to use these
generic accessors with your custom data type.

db48x



reply via email to

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