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 EBf7IwC+o2NOjwAAbAwnHQ (envelope-from ) for ; Thu, 22 Dec 2022 03:16:32 +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 6B30IwC+o2OoCQEAauVa8A (envelope-from ) for ; Thu, 22 Dec 2022 03:16:32 +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 6690C3DC03 for ; Thu, 22 Dec 2022 03:16:31 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p8B87-0004lx-Ic; Wed, 21 Dec 2022 21:16:19 -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 1p8B7r-0004kQ-Jm for guix-patches@gnu.org; Wed, 21 Dec 2022 21:16: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 1p8B7r-0006hv-0S for guix-patches@gnu.org; Wed, 21 Dec 2022 21:16:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p8B7q-000889-KM for guix-patches@gnu.org; Wed, 21 Dec 2022 21:16:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#60225] [PATCH v2 1/2] records: match-record supports specifying a different variable name. References: <20221220174018.14433-1-attila@lendvai.name> In-Reply-To: <20221220174018.14433-1-attila@lendvai.name> Resent-From: Attila Lendvai Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 22 Dec 2022 02:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60225 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 60225@debbugs.gnu.org Cc: Attila Lendvai Received: via spool by 60225-submit@debbugs.gnu.org id=B60225.167167535131227 (code B ref 60225); Thu, 22 Dec 2022 02:16:02 +0000 Received: (at 60225) by debbugs.gnu.org; 22 Dec 2022 02:15:51 +0000 Received: from localhost ([127.0.0.1]:55292 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p8B7e-00087b-Tk for submit@debbugs.gnu.org; Wed, 21 Dec 2022 21:15:51 -0500 Received: from mail-ot1-f42.google.com ([209.85.210.42]:38544) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p8B7d-00087V-Rz for 60225@debbugs.gnu.org; Wed, 21 Dec 2022 21:15:50 -0500 Received: by mail-ot1-f42.google.com with SMTP id p17-20020a9d6951000000b00678306ceb94so331365oto.5 for <60225@debbugs.gnu.org>; Wed, 21 Dec 2022 18:15:49 -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=OqGXTgMuX2+8mYx4/R8M7gaEOjNyyPqL5Q/4WD0Vh08=; b=PW+t/NSVSgNouq4+G69qb/+EGYM9AAls1v8HJTQD5/BoBv95S3QI96mbz/9+NVcdlg ZyIZ5KlO8cfsY2vyBQIcKu3mvwB1HCbs6pNHmR+MGjLOZcgXqv7PYpnr/Yd/mTFCjRYk GmNC0VeBBIYfYuIAccsu+bdVY3nYPPWTMKOJPFIKoR+mcS+J7LUsfoLnDIS6vxr8HYfe KZCDAa3/V9vNSV1bE9rImZ0r+hy5eakhBJnZUZn8y0BfGynXuKYieuJwVrZo+rbm0mIP h5jVr6xVdUZDF5+xAHRS66FFdmbqJ4YkL+VnEzlpz9vPUPCv0/486crnaLkMUzyvP7dC UYCA== 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=OqGXTgMuX2+8mYx4/R8M7gaEOjNyyPqL5Q/4WD0Vh08=; b=opijh7c/ONGo+tSx3mV/6oDNSNGxKhSIwIHo8/DZgCNPC/CcswhrPqU3ASN+MUb0z5 bA60NAoTBYy7U9PFelQVX7SY/Kg66ZtJWGzd6c6JcEST6CsxFKzF5WTcLYWqQEsqytaK H/aB81CiCh5WlSJIpH6xyTmoDaWFUA9xBvwIMYDBurz+W4TLnumqyrQaHGmVWYom+SXX WhPRmqMw4kS5JSpW7OepSFcY1loa5HbHFndNFgGt9MyON2v5iRWHS0G7TTHvgUYsgW8O wItRw917IbWPO2OcVNy/3pzciNzscmiXPm03mPUZNIvT3wYSvyRu91/3A0+XFL3EwO8/ hGdw== X-Gm-Message-State: AFqh2kpcgzt+LuKGWQx/MpXfcJBQsXMNhMiGvw7BDuEsYCcVuwysrQxi jSE8Tk6gkX6ezZon8x6VHHFJFW/epdY= X-Google-Smtp-Source: AMrXdXs4sSnJUlzWUnp3an2wN0G1XG8U0vaGqCQ+Bf+H4OEfilOTCQMpQbUKstqAAhihGDlRlFf+6w== X-Received: by 2002:a9d:480b:0:b0:670:9c6b:e684 with SMTP id c11-20020a9d480b000000b006709c6be684mr1885032otf.22.1671675343787; Wed, 21 Dec 2022 18:15:43 -0800 (PST) Received: from localhost.localdomain ([179.218.10.217]) by smtp.gmail.com with ESMTPSA id k5-20020a544405000000b0035763a9a36csm7361592oiw.44.2022.12.21.18.15.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 18:15:43 -0800 (PST) From: Attila Lendvai Date: Wed, 21 Dec 2022 23:14:55 -0300 Message-Id: <20221222021455.18632-1-attila@lendvai.name> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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-Seal: i=1; s=key1; d=yhetil.org; t=1671675391; a=rsa-sha256; cv=none; b=bzCqy0EtsyhDt1z/txOGFb5nwCI006c8MwYle86sw7zkd3s69r2OcaMFcs+f5negeJ1NAr CbwqzCxSRFLZYzWRO5+bSG+2oDznsXi6SbRIF03hPvfbzhVmALcXEshnRlrSdZ8Yr6seIX rnzcDCPalY+VzJLZETuG2rUJZK73Fi+k0fj5gwFjHaUtEK/R9aZcCxOp6IdeezAYnodbDh wX+53j7Ga1lYkAo3+OtjulrDq6CSIBCievfUdFk3ERzxWfD6Mf96xt5Se23bn0BTdkOeFx cHaVpLP8MNbbj6k1gOhYNAk+zMXxed76P4d+Bs1UV1u3rA6AmYL3HO2YGdt4cA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b="PW+t/NSV"; 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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1671675391; 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:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=OqGXTgMuX2+8mYx4/R8M7gaEOjNyyPqL5Q/4WD0Vh08=; b=aQZ1kMmPXc2ZGdes0XAUIdgG75y744RdDg7moq9QeA44UTST7LB/M4XZr6vwJqjckDti/i GnRbeMt2Wm966NFFAL3ZCMzkgiuXlwH3ZIBfxuzsOxGyMHryU9VT+6ds2fJlYeHhKSLnNC REB3t3H4a1tTaEcudA6TzkpvxWmEU+ANTBDzjUNRGpJ04pco1bZBWnWeUGXjb1BhDEci8m Dm+UvMuFTMNz2rQJ3xXxkfNiqfyLjzPLRF2Iz70KVUl5/I8uMIS8cC+EguYoWlveRUsQZ0 r5nyouoIbFifUpP5aQ+xQHKUPESVO0ThQM4rpxKes6mm/kquVF+iTSE/+hfCbw== X-Spam-Score: -1.80 X-Migadu-Queue-Id: 6690C3DC03 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b="PW+t/NSV"; 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-Scanner: scn0.migadu.com X-Migadu-Spam-Score: -1.80 X-TUID: tCHAc0CWzRm1 An example: (match-record obj (field1 (field2 custom-var-name) field3) ...) * guix/records.scm (match-record-inner): Add support for the new syntax. * tests/records.scm ("match-record, simple"): Add a simple test case for the new syntax. --- guix/records.scm | 9 ++++++--- tests/records.scm | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/guix/records.scm b/guix/records.scm index 13463647c8..1f097c7108 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 variable) rest ...) body ...) + #'(let-syntax ((field-offset (syntax-rules () ((_ f) (lookup-field field 0 f))))) (let* ((offset (type map-fields field-offset)) - (field (struct-ref record offset))) + (variable (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 ...))))) diff --git a/tests/records.scm b/tests/records.scm index 8504c8d5a5..b1203dfeb7 100644 --- a/tests/records.scm +++ b/tests/records.scm @@ -540,8 +540,8 @@ (define-record-type* foo make-foo (first second) (list first second)) (match-record (foo (first 'a) (second 'b)) - (second first) - (list first second))))) + (second (first first/new-var)) + (list first/new-var second))))) (test-equal "match-record, unknown field" 'syntax-error -- 2.35.1