From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id 4L0yDIgcTGTVKQEASxT56A (envelope-from ) for ; Fri, 28 Apr 2023 21:20:40 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id 6Ak0DIgcTGQ4ggAA9RJhRA (envelope-from ) for ; Fri, 28 Apr 2023 21:20:40 +0200 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 0C24E42094 for ; Fri, 28 Apr 2023 21:20:40 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psTda-0002Ra-TH; Fri, 28 Apr 2023 15:20:11 -0400 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 1psTdT-0002PN-Tx for guix-patches@gnu.org; Fri, 28 Apr 2023 15:20:05 -0400 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 1psTdT-0004JV-Di for guix-patches@gnu.org; Fri, 28 Apr 2023 15:20:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1psTdT-00063Q-8h for guix-patches@gnu.org; Fri, 28 Apr 2023 15:20:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#63135] [PATCH v2 5/5] records: Add MATCH-RECORD-LAMBDA. Resent-From: "(" Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 28 Apr 2023 19:20:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63135 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 63135@debbugs.gnu.org Cc: "\(" , Josselin Poiret Received: via spool by 63135-submit@debbugs.gnu.org id=B63135.168270956123138 (code B ref 63135); Fri, 28 Apr 2023 19:20:03 +0000 Received: (at 63135) by debbugs.gnu.org; 28 Apr 2023 19:19:21 +0000 Received: from localhost ([127.0.0.1]:34538 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1psTcm-000615-UH for submit@debbugs.gnu.org; Fri, 28 Apr 2023 15:19:21 -0400 Received: from knopi.disroot.org ([178.21.23.139]:41768) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1psTck-00060H-Us for 63135@debbugs.gnu.org; Fri, 28 Apr 2023 15:19:19 -0400 Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 358B44021E; Fri, 28 Apr 2023 21:19:18 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from knopi.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PBCvUDFffq0U; Fri, 28 Apr 2023 21:19:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1682709556; bh=73P5wsZTJ6hDn+xXhAEBY6bfYosiRAiY3VVjTHHz1Kc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QEmJ9uKAGI2WWRhC/AzyLSwDXXpqjvEavfsvFFmtHoxmGC1PImlcalhxVI+rHY7K5 QqLGZ9g5XvN4rEEhhe+AKChydkBNT/+91maEKHCKuydP1jer7FJAyPJAcqPgcyXz+K m7ismylrMj5nei/N+0dAnOkI4IQsxKxpCR+4sCJL8ZsvjKH+cjWkyEIUNx792Knd4o pexECYPS257XJB1MVw2Ap+Gy8sRbtHZcS1bEKsM53bvOunjeWrbXhFrkujNTHpbJvf xYmktTxyDsY3Xf8ksJsXwCJLctJVDyiBlIxrYFtwmhVTNGCQjjV48nSqfa48VYMACB x6miogJY9AHgw== Date: Fri, 28 Apr 2023 20:19:05 +0100 Message-Id: <20230428191905.13860-6-paren@disroot.org> In-Reply-To: <20230428191905.13860-1-paren@disroot.org> References: <20230428191905.13860-1-paren@disroot.org> 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: , Reply-to: "\(" X-ACL-Warn: , "\( via Guix-patches" From: "\( via Guix-patches" via 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=1682709640; a=rsa-sha256; cv=none; b=b4oyA6X7pl5NoNsBrSyU2nN4R+asfeGYRatjDm4smAz2CxGip9lynAIrmrYXb28c4FBWRU KNVyLj9qWXQ4FebzUqpWFMYTEn2H8gClRxa0krewrgI1RlcrjRAZLhYaiPDmSbvWG7SEbF 9z53NW2obcg+55XptCZr1Hj0H3OO/MwdEoHvKfzjQYeBfk0EsxGmGZQDI5VAY+g+Gg0A8R pR6VQ3egIBsjA+GEWa8Ud2gm9cwnW1iUmhCzLbfcq0R/UsbBiub5Ai2DvxOnY7xPWIsCbN 6dKMMDtfjSrfIuaa2xgcvkl5ih8CLcAPEqycLRBwOz1csM5Rlfd6pFp4mmoSeg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=disroot.org header.s=mail header.b=QEmJ9uKA; dmarc=pass (policy=none) header.from=gnu.org; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1682709640; h=from:from:sender:sender:reply-to: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=5IXny2bB1qPFlzhZtMqDzftBBSmoZWf9djSGoYRLDW4=; b=a/1eAVsI6UBatday+ydf7C+UdL6uk7B6q0jyRFvKU/fK7bTZha8LgJghUVvKZCIJeI2vud CkBV05/iyUP43qI4zeOaiILqZof2uyxp/kSOD7hwKDjXnouXyQFaA08KYewEgvf4O1CUTB 8Os3fIl499Z1/tsBWuc0aA3jY5sLoCFx8N1SIo68He54TjTAfdsOl12KM02txEZ7g+ZVl2 yWJVuPmVgBN3225YuRaT/ugXbmMi/k7l0puipzDIY0GkELq/NuBQhzP7GYXgL8cvBY+RC6 19z+PoVz8g1hNuXZ9uSEHu+LtUZHgUxmE98lmZv1iONPm1qhaJUeN9yu3YCqgQ== X-Migadu-Spam-Score: -2.21 X-Spam-Score: -2.21 X-Migadu-Queue-Id: 0C24E42094 X-Migadu-Scanner: scn0.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=disroot.org header.s=mail header.b=QEmJ9uKA; dmarc=pass (policy=none) header.from=gnu.org; 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" X-TUID: v2xAGUywVskE * guix/records.scm (match-record-lambda): New syntax. * tests/records.scm ("match-record-lambda"): New test. --- .dir-locals.el | 1 + guix/records.scm | 15 ++++++++++++++- tests/records.scm | 12 ++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.dir-locals.el b/.dir-locals.el index 3ffd25ee94..d79b5c9d7e 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -71,6 +71,7 @@ (eval . (put 'lambda* 'scheme-indent-function 1)) (eval . (put 'substitute* 'scheme-indent-function 1)) (eval . (put 'match-record 'scheme-indent-function 3)) + (eval . (put 'match-record-lambda 'scheme-indent-function 2)) ;; TODO: Contribute these to Emacs' scheme-mode. (eval . (put 'let-keywords 'scheme-indent-function 3)) diff --git a/guix/records.scm b/guix/records.scm index 041eb2f297..504a023e87 100644 --- a/guix/records.scm +++ b/guix/records.scm @@ -31,7 +31,8 @@ (define-module (guix records) alist->record object->fields recutils->alist - match-record)) + match-record + match-record-lambda)) ;;; Commentary: ;;; @@ -642,4 +643,16 @@ (define-syntax match-record (match-record-inner #,s record type (fields ...) body ...) (throw 'wrong-type-arg record)))))) +(define-syntax match-record-lambda + (lambda (s) + "Return a procedure accepting a single record of the given TYPE for which each +FIELD will be bound to its FIELD name within the returned procedure. A syntax error +is raised if an unknown field is queried." + (syntax-case s () + ((_ type (field ...) body ...) + #`(lambda (record) + (if (eq? (struct-vtable record) type) + (match-record-inner #,s record type (field ...) body ...) + (throw 'wrong-type-arg record))))))) + ;;; records.scm ends here diff --git a/tests/records.scm b/tests/records.scm index 4f0aeb3903..8ee306bddc 100644 --- a/tests/records.scm +++ b/tests/records.scm @@ -590,4 +590,16 @@ (define-record-type* with-thunked make-with-thunked (match-record rec (normal thunked) (list normal thunked))))) +(test-equal "match-record-lambda" + '("thing: foo" "thing: bar") + (begin + (define-record-type* with-text make-with-text + with-text? + (text with-text-text)) + + (map (match-record-lambda (text) + (string-append "thing: " text)) + (list (with-text (text "foo")) + (with-text (text "bar")))))) + (test-end) -- 2.39.2