[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Shouldn't records be sequences?
From: |
Clément Pit-Claudel |
Subject: |
Re: Shouldn't records be sequences? |
Date: |
Sun, 12 Apr 2020 14:49:24 -0400 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 |
On 12/04/2020 13.23, Stefan Monnier wrote:
>> A recent example: I have a list of records that I display to users,
>> using a custom sort order (a list of record fields). It's convenient
>> to be able to go from list of fields to list of array offsets once,
>> and then use those offsets in the comparison function (this is similar
>> to what I'd do with C structs).
>
> Not sure how that relates to treating them as sequences.
> We do want some way to work at the lower level (i.e. access the N'th
> field), which is currently done with `aref` but could be done by
> a `record-ref` instead.
Depends what you mean by sequence, I guess. I usually think of a sequence as
anything having an 'nth', so once you have a record-ref that takes an offset
and returns a value, you might as well call that seq-elt.
> PS: The clean equivalent in Elisp would be to use a list of
> field-accessors instead of a list of fields. This also saves you from
> converting to a list of array offsets. But (funcall accessor x) is
> probably significantly slower than (aref x offset), indeed.
That's the exact issue I ran into, yes.
(Well, and the fact that the existence of cl-struct-slot-offset makes it easy
to get the offset of a field, and I couldn't find a corresponding primitive to
get an accessor function).
Python solves this issue by having special "accessor" objects that are faster
to call than the corresponding lambdas ("itemgetter")