From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: =?UTF-8?Q?Cl=c3=a9ment_Pit-Claudel?= Newsgroups: gmane.emacs.devel Subject: Re: Shouldn't records be sequences? Date: Sun, 12 Apr 2020 14:49:24 -0400 Message-ID: References: <871rotdp21.fsf@gmail.com> <0e837a01-0d38-27e2-179c-e6aca1872248@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="46488"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Apr 12 20:50:01 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jNhg7-000Bz8-WC for ged-emacs-devel@m.gmane-mx.org; Sun, 12 Apr 2020 20:50:00 +0200 Original-Received: from localhost ([::1]:36054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jNhg7-000683-1p for ged-emacs-devel@m.gmane-mx.org; Sun, 12 Apr 2020 14:49:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56774) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jNhfc-0005eZ-MW for emacs-devel@gnu.org; Sun, 12 Apr 2020 14:49:29 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jNhfb-0007gi-Mw for emacs-devel@gnu.org; Sun, 12 Apr 2020 14:49:28 -0400 Original-Received: from mail-qv1-xf2e.google.com ([2607:f8b0:4864:20::f2e]:40713) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jNhfb-0007gL-HC for emacs-devel@gnu.org; Sun, 12 Apr 2020 14:49:27 -0400 Original-Received: by mail-qv1-xf2e.google.com with SMTP id k9so3463123qvw.7 for ; Sun, 12 Apr 2020 11:49:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=5PPIRRcyAsJ4rRoL8oNLlxnz3A5E7qQZH5YpgiU0Dxo=; b=Lzq7/t0DDeiX0MwIs1YtequZX++GCMvjfy4Uo863bQdBAMxiVYdm1VzyjdfbUv1N8K qflmaIFR2KWTmrm06s2dqCATlLXgQ5KfBwORCAAUQCLIoQTWOoCzQhCTNxaiu5uFU3c2 kaLmfppUFuoodsxy47RBNgKGogCZwqrXOCJlypDkXgjNNKNnAVuYZ9nGLy8qjgqMhnBI odq640XwEGd0NW4Tl/DXXvtFW0+eCbjVpAq5qAtZ1nuegz+FToKaBLgmjliFkANq9Sig FZCHc02RNO/SEISUKp9XI3njCwhSL652P4s6ty3gmfg3S+mi8bEiBYypE9wgpxqVPuPZ 8OIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=5PPIRRcyAsJ4rRoL8oNLlxnz3A5E7qQZH5YpgiU0Dxo=; b=VIK5iGQDPST3eksO83mm42vurj8r+0JnXNz16Qgbnf+EZy7HWb9IHQTUECvpHddqlg W1FtCWHurG50i0p0EinKloq1F0VfeireQ3S4I78VGnA4Gq8a9M4qOO0acJKgpl8hbEa1 KQp+BlkDl5aiivsraOdlctD5FGyEx8th6ga8lQPrEiOWtKuyHba3DsvRfXvMSkGWEWao ZvSXJUMaGk4Q5rq4QjxkxGdzMKPTX3AKGtzXx2uPwwDzghMC8LXZo/dw4UBbcTzxrTaI E7WR9eGrdgxYZIXeLEw00hFiyWc66cXdechgql1KtThn/0WIF9EYM0kROLGq7TPemR1F 6uTg== X-Gm-Message-State: AGi0PuZdUA0Cn19su1gAK/khuEGD8wwT/WkGJ/VY4yQNehZEiH4tdXGP N7BT1eRrz3m/cxc81i1/oGM7Lqpl X-Google-Smtp-Source: APiQypIQrYaLs9jFtMtI0Yc9tbmmRTr0iDJrq914FuPpdGPsnxNEKvxnxtZXgb/AsoV6F1EMJCzE0A== X-Received: by 2002:a0c:ba9b:: with SMTP id x27mr14640786qvf.194.1586717366088; Sun, 12 Apr 2020 11:49:26 -0700 (PDT) Original-Received: from ?IPv6:2601:184:4180:66e7:a4a6:abeb:cc22:e19f? ([2601:184:4180:66e7:a4a6:abeb:cc22:e19f]) by smtp.googlemail.com with ESMTPSA id s32sm6797440qth.43.2020.04.12.11.49.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Apr 2020 11:49:25 -0700 (PDT) In-Reply-To: Content-Language: en-GB X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::f2e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:246873 Archived-At: 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")