From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id +JYLEND8oWN47wAAbAwnHQ (envelope-from ) for ; Tue, 20 Dec 2022 19:20:00 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id gCniD9D8oWOsnQAAauVa8A (envelope-from ) for ; Tue, 20 Dec 2022 19:20:00 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id AA88812598 for ; Tue, 20 Dec 2022 19:19:59 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7gcv-0002fl-Bp; Tue, 20 Dec 2022 12:42:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7gct-0002fY-77 for guix-patches@gnu.org; Tue, 20 Dec 2022 12:42:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p7gcs-0007jo-Uu for guix-patches@gnu.org; Tue, 20 Dec 2022 12:42:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p7gcs-0001Fr-GV for guix-patches@gnu.org; Tue, 20 Dec 2022 12:42:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#60225] [PATCH] records: match-record supports specifying a different variable name. Resent-From: Attila Lendvai Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 20 Dec 2022 17:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 60225 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 60225@debbugs.gnu.org Cc: Attila Lendvai X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16715580824802 (code B ref -1); Tue, 20 Dec 2022 17:42:02 +0000 Received: (at submit) by debbugs.gnu.org; 20 Dec 2022 17:41:22 +0000 Received: from localhost ([127.0.0.1]:46197 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p7gcE-0001FO-IM for submit@debbugs.gnu.org; Tue, 20 Dec 2022 12:41:22 -0500 Received: from lists.gnu.org ([209.51.188.17]:48992) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p7gcC-0001FI-Os for submit@debbugs.gnu.org; Tue, 20 Dec 2022 12:41:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7gcC-0002X1-EL for guix-patches@gnu.org; Tue, 20 Dec 2022 12:41:20 -0500 Received: from mail-oo1-xc2d.google.com ([2607:f8b0:4864:20::c2d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p7gcA-0007gw-7F for guix-patches@gnu.org; Tue, 20 Dec 2022 12:41:20 -0500 Received: by mail-oo1-xc2d.google.com with SMTP id e11-20020a4ab14b000000b0049be568062bso2003535ooo.4 for ; Tue, 20 Dec 2022 09:41:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=X7pN8iTBG4c7zeirHnZZl+77E9qcU3133vXnV7hdG4U=; b=OJlMR2S75QRIevXqD3jUY0xBC7Sfh7OoVMtpmYBrRsOJsTIHy57QS6RtzAL4tdmF5C DhX9O/RYaKHjZUq12/fT7f9c/a6ElwVBh5Eu7ptON9J8h7pvZNLDXdweHFphVfcM5fEr zZ4eg56fGjMj+dVFv9LoWttn9AvQezXuMuwgMdaBtFGPHvvrKg/xJTYW7E3Nw5KU/YFi gInnUzR0XE3iiavLLOHxZAgrzyFcJCE/oL1dksRLhvV/97cgBRqCOeD7gtr17d8jL+C6 7zNWI19g9CaFtmOVUSbhZRTZXYvPxdGHpkrQYJVvW+c/iw7npd2aj3JMYzQ57c3lPl0r gB6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=X7pN8iTBG4c7zeirHnZZl+77E9qcU3133vXnV7hdG4U=; b=uBOh1xwPys2Zy/odA96tT1OPOc+7/Jb17hsAJ6nTewB3Rtlqsp0dduxgn9FtOHoBXY 1L32hsfX8Izmcr1nMcqVFnAXvwXgI/W2ktCmt6UNAP22ymO+S2D+neWPk/jbBWZbQGTR /27hDo/4E+0xP6zfIjXGX8sMvbYhpPk1DxnW4WpoOJm/vtDyLOIhyM7zN1tQ17Xm35// Q1sT/XiVj21mBv0ZcYhs4daZv4B9zPR1ClN5xv7Gq4XQNj6eMlc+3qdsVzguqR6DesnL ZNQA7NvZr4c/1vNOzusNB+o6P+duNAHkSaqRwJ3f9z3LNtA6OLMDnacNpVPvojg4M2Y7 MZsQ== X-Gm-Message-State: AFqh2ko8r55xtRku1eNjNdfyWqvk59KKkMvVy0cSrnq4zKSC2G9VO5wT 3JatXoKcT2z0MLMitlhI/57ITW+qXAs= X-Google-Smtp-Source: AMrXdXv7nZ8nVcnX/bdF7l3bNu7IHoY+icKlqYIUseI8aQWNX4irBSCqSneUkScZ8UQD6M8eiikNSw== X-Received: by 2002:a4a:4fcd:0:b0:4a3:f16e:3d0c with SMTP id c196-20020a4a4fcd000000b004a3f16e3d0cmr5318769oob.0.1671558076514; Tue, 20 Dec 2022 09:41:16 -0800 (PST) Received: from localhost.localdomain ([179.218.10.217]) by smtp.gmail.com with ESMTPSA id g11-20020a4ad84b000000b004a09df5a1dbsm5286329oov.8.2022.12.20.09.41.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Dec 2022 09:41:15 -0800 (PST) From: Attila Lendvai Date: Tue, 20 Dec 2022 14:40:19 -0300 Message-Id: <20221220174018.14433-1-attila@lendvai.name> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::c2d; envelope-from=attila.lendvai@gmail.com; helo=mail-oo1-xc2d.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=OJlMR2S7; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Seal: i=1; s=key1; d=yhetil.org; t=1671560400; a=rsa-sha256; cv=none; b=qrgDSBIcXoTFrp5k6yuGqGsvcSJfXbt1yiyJGZRHCsF3EsEAbvE6Uov8rx5TSkYK6Wi3Hw SduWq6mkjQKEM6+3pzB6DkVonNJUF1ZCLrV4aheBYliy+eD78S7oPZmR2YcZsXxz2BRsdK p4pO/7cjGWWYXymaX2Oq53NGsNmMEU1AdpAoNmrEAS56PpY0fNQ+mEaaiC/xUQpNXViZD/ eO7Xhs/SZ/jNwT4T3sXdrtJ8QVqyBLWm6+fi7Yy3CY5tGDHWu+jMWuMySaBg1r7RWhbckC 6L2BHviCMlSqmFSK94xywsZKarlOax09+A4N8o+RP1LJyFDJ5EOTRhGuohJTJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1671560400; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=X7pN8iTBG4c7zeirHnZZl+77E9qcU3133vXnV7hdG4U=; b=LThP3CN7jBWo2N4QG+Aw0l1g85WXhIeMRZLCNOslu8nI0pCDDqNu4Ft7bHjaDBTOEzqJmp /FgVgkfinHfza2Unvg6sHgsCgkAK5dTRwJahmI7Hq/csAsQugR+PNFuHrejgpCq0jxODz/ iWXp0v1xbbR/0Rwl7GlQVWNkkdPykbPZYS0TPqZZ1aUncC64/A3dv2/2bNMOt4f07/uGhY V5CsXw9CNYLJs7tWYA4gYrAoJAvXOOV9kUf0aWBUHUDucPCEMTG73vYOo+7wR7JKi6uYaE uClXzpGCHmCaoLfQEAWXnL308XpLgFWOeD3ire7gkj4FTG7WFk0a0GyX31xctw== X-Migadu-Scanner: scn0.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=OJlMR2S7; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=none X-Migadu-Spam-Score: 0.11 X-Spam-Score: 0.11 X-Migadu-Queue-Id: AA88812598 X-TUID: 9EkFHEcMdmwx An example: (match-record obj (field1 (field2 custom-var-name) field3) ...) --- guix/records.scm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/guix/records.scm b/guix/records.scm index 13463647c8..0b2487a156 100644 --- a/guix/records.scm +++ b/guix/records.scm @@ -592,13 +592,16 @@ (define-syntax lookup-field (define-syntax match-record-inner (lambda (s) (syntax-case s () - ((_ record type (field rest ...) body ...) - #`(let-syntax ((field-offset (syntax-rules () + ((_ record type ((field-name variable-name) rest ...) body ...) + #'(let-syntax ((field-offset (syntax-rules () ((_ f) - (lookup-field field 0 f))))) + (lookup-field field-name 0 f))))) (let* ((offset (type map-fields field-offset)) - (field (struct-ref record offset))) + (variable-name (struct-ref record offset))) (match-record-inner record type (rest ...) body ...)))) + ((_ record type (field rest ...) body ...) + ;; Redirect to the canonical form above. + #'(match-record-inner record type ((field field) rest ...) body ...)) ((_ record type () body ...) #'(begin body ...))))) -- 2.35.1