From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id eNBVKkkWvmFZdQAAgWs5BA (envelope-from ) for ; Sat, 18 Dec 2021 18:11:37 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id QODhJUkWvmFKGAAAbx9fmQ (envelope-from ) for ; Sat, 18 Dec 2021 17:11:37 +0000 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 6A9B112675 for ; Sat, 18 Dec 2021 18:11:37 +0100 (CET) Received: from localhost ([::1]:51302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mydFA-0003Oz-7M for larch@yhetil.org; Sat, 18 Dec 2021 12:11:36 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mydEc-0003Nv-Dr for guix-patches@gnu.org; Sat, 18 Dec 2021 12:11:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:60401) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mydEc-0000K1-5C for guix-patches@gnu.org; Sat, 18 Dec 2021 12:11:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mydEc-0005B9-07 for guix-patches@gnu.org; Sat, 18 Dec 2021 12:11:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#52603] [PATCH 1/2] combinators: Add 'define-compile-time-procedure'. References: <20211218170227.19999-1-ludo@gnu.org> In-Reply-To: <20211218170227.19999-1-ludo@gnu.org> Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 18 Dec 2021 17:11:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 52603 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 52603@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 52603-submit@debbugs.gnu.org id=B52603.163984745719890 (code B ref 52603); Sat, 18 Dec 2021 17:11:01 +0000 Received: (at 52603) by debbugs.gnu.org; 18 Dec 2021 17:10:57 +0000 Received: from localhost ([127.0.0.1]:43712 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mydEX-0005Ak-D0 for submit@debbugs.gnu.org; Sat, 18 Dec 2021 12:10:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38002) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mydEV-0005AO-EZ for 52603@debbugs.gnu.org; Sat, 18 Dec 2021 12:10:56 -0500 Received: from [2001:470:142:3::e] (port=59256 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mydEQ-0000Fx-8E; Sat, 18 Dec 2021 12:10:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=sZPtlVu7O9kWRcWDKdsLxqBQTJwfevg1mscj9qDhRMY=; b=Ni7pyCQaJPlmPd JWNkHS5GWsUcZUDFOyKe3q7aDa2Q6fk0w0bpc+uT2JwFP/JI7zwGuH/YpRlcCTaeMAY4a7bo7Afa7 pFXVaGZAvpBRKrWzFc74qsXWXNFsq8PXbG2uk/Jq2J3yz6QpBo7xOf7R3WaLvGsbadGO5f8yOx6aI GLkZXEqMEJikVWXo4qCrf6TPayuLBLWGBvE264lkLoDJfh9djB0pPVOTXQrVxHhuFtqs2FqnNFQiT epEhxfI+gYerK/+BFhGHs77kiYVjNDohBbyFVyQAFInwZlbXKYIOym8WD25WGFStk24s/HThU3TLX eSxyiHj63jS/F+vyky8g==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:51822 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mydEQ-0007OB-4q; Sat, 18 Dec 2021 12:10:50 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Sat, 18 Dec 2021 18:10:39 +0100 Message-Id: <20211218171040.20268-1-ludo@gnu.org> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1639847497; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: 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=sZPtlVu7O9kWRcWDKdsLxqBQTJwfevg1mscj9qDhRMY=; b=e5LKipasNIfYkJZjRr7SPDSAi/yB8v+486BoylX9ahmfhC06OStJ/UIPbBF/Pxzy2uxeHx 371y3X4++qeF+26pltWCXOGRZvDps12vPwzGy4AwOQiahI4KoGl0kppS7ljqOubYT2M+Zb O6Dsp5S7aX0wwxOMqyjEPdMdj+Qk+3sCgXrctv1jgZsXYa5QW6FF7TzMMba+dBAsimIKky 3Yr6D7wu8DvRwS3dRiWYLcS9xXCu4Cliemx3GG7cLgOTN9ao1nUtukMPo0egcugoGPotAX QOM7kWsZ0aaeWVvG2O+yeZWY20m1btcHOwii//NesGNU3z+dyW+Y8QRRiq+BAg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1639847497; a=rsa-sha256; cv=none; b=dK0RkBd5T7ukuGtFv+MWtchWCqCbv4ilL1rGiQk2b41U2hHl8SMnEEBlAwGAyXdUyccKXX JDN5a1Mk9FPA4Bzw5pqhMc1pZxz3bsTH+hRVsS+tWuU8gWjZCsJSTRU362IxenFqlCfqW2 dpC5Vfrxin4lLLG2ivhXsXE0oHJqlL3v2FKTsgeofFpyF33JbH6kr8oNGwxgpNF2u8uMTP ctY75sFmeNxygJQ3OWniKdYGnqcKHcIcCS9xVD6058ECza5iWBQ3wHQSBNadqCsMVeOrmy EdMzYNq5gCCiWstNuuplgozG5/i0gRhSgcmbdK9lB/o9MXQqmetqYH+BBNFLRg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=Ni7pyCQa; 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-Migadu-Spam-Score: -3.21 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=Ni7pyCQa; 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-Migadu-Queue-Id: 6A9B112675 X-Spam-Score: -3.21 X-Migadu-Scanner: scn0.migadu.com X-TUID: iRC3nddo1W0B * guix/combinators.scm (procedure-call-location): New syntax parameter. (define-compile-time-procedure): New macro. --- guix/combinators.scm | 50 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/guix/combinators.scm b/guix/combinators.scm index 88ad09dbe6..261d6bb57e 100644 --- a/guix/combinators.scm +++ b/guix/combinators.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017 Ludovic Courtès +;;; Copyright © 2012-2017, 2021 Ludovic Courtès ;;; Copyright © 2014 Eric Bavier ;;; Copyright © 2020 Arun Isaac ;;; @@ -24,7 +24,9 @@ (define-module (guix combinators) #:export (fold2 fold-tree fold-tree-leaves - compile-time-value)) + compile-time-value + procedure-call-location + define-compile-time-procedure)) ;;; Commentary: ;;; @@ -100,4 +102,48 @@ (define-syntax compile-time-value ;not quite at home (_ #`'#,(datum->syntax s val))))))) v)))) +(define-syntax-parameter procedure-call-location + (lambda (s) + (syntax-violation 'procedure-call-location + "'procedure-call-location' may only be used \ +within 'define-compile-time-procedure'" + s))) + +(define-syntax-rule (define-compile-time-procedure (proc (arg pred) ...) + body ...) + "Define PROC as a macro such that, if every actual argument in a \"call\" +matches PRED, then BODY is evaluated at macro-expansion time. BODY must +return a single value in a type that has read syntax--e.g., numbers, strings, +lists, etc. + +BODY can refer to 'procedure-call-location', which is bound to a source +property alist corresponding to the call site. + +This macro is meant to be used primarily for small procedures that validate or +process its arguments in a way that may be equally well performed at +macro-expansion time." + (define-syntax proc + (lambda (s) + (define loc + #`(identifier-syntax + '#,(datum->syntax #'s (syntax-source s)))) + + (syntax-case s () + ((_ arg ...) + (and (pred (syntax->datum #'arg)) ...) + (let ((arg (syntax->datum #'arg)) ...) + (syntax-parameterize ((procedure-call-location + (identifier-syntax (syntax-source s)))) + body ...))) + ((_ actual (... ...)) + #`((lambda (arg ...) + (syntax-parameterize ((procedure-call-location #,loc)) + body ...)) + actual (... ...))) + (id + (identifier? #'id) + #`(lambda (arg ...) + (syntax-parameterize ((procedure-call-location #,loc)) + body ...))))))) + ;;; combinators.scm ends here -- 2.33.0