From patchwork Thu Dec 22 02:14:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Attila Lendvai X-Patchwork-Id: 45502 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 14C1227BBED; Thu, 22 Dec 2022 02:16:34 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 6A66B27BBE9 for ; Thu, 22 Dec 2022 02:16:31 +0000 (GMT) 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 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+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches 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 From patchwork Thu Dec 22 02:14:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Attila Lendvai X-Patchwork-Id: 45503 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id B8AAB27BBED; Thu, 22 Dec 2022 02:18:15 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 8F51827BBE9 for ; Thu, 22 Dec 2022 02:18:11 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p8B9t-00058q-U9; Wed, 21 Dec 2022 21:18:09 -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 1p8B9m-00058P-CL for guix-patches@gnu.org; Wed, 21 Dec 2022 21:18:05 -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 1p8B9m-0006za-3c for guix-patches@gnu.org; Wed, 21 Dec 2022 21:18:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p8B9l-00089R-Sb for guix-patches@gnu.org; Wed, 21 Dec 2022 21:18:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#60225] [PATCH v2 2/2] tests: records: Add a failing test for match-record. Resent-From: Attila Lendvai Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 22 Dec 2022 02:18:01 +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.167167544131317 (code B ref 60225); Thu, 22 Dec 2022 02:18:01 +0000 Received: (at 60225) by debbugs.gnu.org; 22 Dec 2022 02:17:21 +0000 Received: from localhost ([127.0.0.1]:55302 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p8B97-000893-Bm for submit@debbugs.gnu.org; Wed, 21 Dec 2022 21:17:21 -0500 Received: from mail-oi1-f171.google.com ([209.85.167.171]:41549) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p8B95-00088v-GI for 60225@debbugs.gnu.org; Wed, 21 Dec 2022 21:17:19 -0500 Received: by mail-oi1-f171.google.com with SMTP id i127so749371oif.8 for <60225@debbugs.gnu.org>; Wed, 21 Dec 2022 18:17:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=ML+g7edwdiyUjQc+UNmpnbSSNI8fh+l0uRMUzrNdaCg=; b=poViqPcuviv4yWkqDQrGWp0yO18tXOVNWgfQIY6OTsfK2pHUi+sPB+XwR7cZ75yb4d TSPdH0y5rWHLNYUOvAKTb+OfbLLfc3adO58TL0ULgafcy6XXGSbpCXKAham9tp2gz5tC 2PMRRHNNELo1OsHU44Rm08mfVGxdhDYeuJWrZjIFKLFIg5YRhKWgF+jrfCGzn5kTpDrh j8K6Q23B9ilFagGJ7LhjgxVubcvGfYMM2YeZk4spa94fTSaYqWCuvbrUR6F5htZAfJgF P3KZUQ6yVDy6SD+h90UQCDRpPFyIsrBJ3ZCnJe0KDuWYwF8I/5vFGw6DMeSh3lt++Snj Rgxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ML+g7edwdiyUjQc+UNmpnbSSNI8fh+l0uRMUzrNdaCg=; b=wpa0K9p8kMN+z/+kIxXJOhHCnpsz68x3bz22BjAsuSOQ6KKV0lZpRfGL7J5+OUSqRz xxY1OHaOIFDIXJrBpM3Ltji20TSdIVbfFpxmnViusIeOOhi6Ka+ZKN9IJiVOTWYvzPR8 wQ4j8v0gH+CUnB0H7KNa1SlUagsYlHvM0gy3KEU2EDZNYctTRzgfoaDQO693f+CqO9mi fkv/+dKR0faJUzsVxQaQPyJHPELY8QI6EadChtdE/M5zfKLWzR1qM2AZfSxzY6DR9ti2 4+qNZflbFy93752KjCLNS+f2/QgepVrJ2XiADSfiBo6XyGDsXohgwF/yULsOZAnS5Jqm w7CQ== X-Gm-Message-State: AFqh2kotrWJLpHubUQ1t+rdlkP6Yd4JnON2mcEC/xQp22MD0vQYk3Zus x1KkmQe3yPfNoDjaIgJI0sHbbE4TN1c= X-Google-Smtp-Source: AMrXdXsooxE+ba2hGxJAiYpT4p/ckezeB6iCLQ7jWn1+9CgD9FVGRF45ytrdyd9id1Rc+ivzP5FXyQ== X-Received: by 2002:a05:6808:21a7:b0:35c:492d:27ad with SMTP id be39-20020a05680821a700b0035c492d27admr2515028oib.30.1671675433995; Wed, 21 Dec 2022 18:17:13 -0800 (PST) Received: from localhost.localdomain ([179.218.10.217]) by smtp.gmail.com with ESMTPSA id k5-20020a544405000000b0035763a9a36csm7361592oiw.44.2022.12.21.18.17.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 18:17:13 -0800 (PST) From: Attila Lendvai Date: Wed, 21 Dec 2022 23:14:57 -0300 Message-Id: <20221222021455.18632-2-attila@lendvai.name> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221222021455.18632-1-attila@lendvai.name> References: <20221222021455.18632-1-attila@lendvai.name> MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * tests/records.scm ("match-record, syntactic interference"): New failing test. --- i'm not sure what's going on here, but it looks like a bug to me. i've experienced this in real code, and the error message was not very helpful. tests/records.scm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/records.scm b/tests/records.scm index b1203dfeb7..8a48e2fd07 100644 --- a/tests/records.scm +++ b/tests/records.scm @@ -561,4 +561,27 @@ (define-record-type* foo make-foo (make-fresh-user-module))) (lambda (key . args) key))) +(test-expect-fail 1) +(test-equal "match-record, syntactic interference" + '(1 2) + (begin + (define* (make-form #:optional (bindings '())) + `(begin + (use-modules (guix records)) + + (let ((first 42)) ; here it does not interfere + (define-record-type* foo make-foo + foo? + (first foo-first (default 1)) + (second foo-second)) + + (let (,@bindings) ; but here it does interfere + (match-record (foo (second 2)) + (first second) + (list first second)))))) + ;; This works fine. + (eval (make-form) (make-fresh-user-module)) + ;; But this fails, although I think it shouldn't. + (eval (make-form '((second 43))) (make-fresh-user-module)))) + (test-end)