From mboxrd@z Thu Jan 1 00:00:00 1970 From: taylanbayirli@gmail.com (Taylan Ulrich =?utf-8?Q?Bay=C4=B1rl=C4=B1?= =?utf-8?Q?=2FKammer?=) Subject: Re: Some macros to make package definitions prettier Date: Thu, 26 Feb 2015 12:07:47 +0100 Message-ID: <877fv553ss.fsf@taylan.uni.cx> References: <874mqa6iz4.fsf@taylan.uni.cx> <87bnkhzhxd.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58594) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQwIK-0004z6-BQ for guix-devel@gnu.org; Thu, 26 Feb 2015 06:07:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YQwIJ-0006TW-8y for guix-devel@gnu.org; Thu, 26 Feb 2015 06:07:52 -0500 In-Reply-To: <87bnkhzhxd.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Thu, 26 Feb 2015 00:32:14 +0100") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: Ludovic =?utf-8?Q?Court=C3=A8s?= Cc: guix-devel@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable ludo@gnu.org (Ludovic Court=C3=A8s) writes: > taylanbayirli@gmail.com (Taylan Ulrich "Bay=C4=B1rl=C4=B1/Kammer") skribi= s: > >> (modify-phases '((foo . 0) (bar . 1) (baz . 2)) >> (delete foo) >> (replace bar 'x) >> (add-before baz pre-baz 'y)) ;=3D> ((bar . x) (pre-baz . y) (baz . 2)) > > I like it! Let=E2=80=99s put it in (guix utils)? Shouldn't it go to (guix build utils)? Here's a patch: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-utils-Add-modify-phases.patch Content-Description: patch >From 320a974e9b04959544bb93c67766957541ec02ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Taylan=20Ulrich=20Bay=C4=B1rl=C4=B1/Kammer?= Date: Thu, 26 Feb 2015 11:51:11 +0100 Subject: [PATCH] utils: Add 'modify-phases'. * guix/build/utils.scm (modify-phases): New macro. --- guix/build/utils.scm | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/guix/build/utils.scm b/guix/build/utils.scm index 4407f9a..c35966f 100644 --- a/guix/build/utils.scm +++ b/guix/build/utils.scm @@ -54,6 +54,7 @@ alist-cons-before alist-cons-after alist-replace + modify-phases with-atomic-file-replacement substitute substitute* @@ -423,6 +424,33 @@ An error is raised when no such pair exists." ((_ after ...) (append before (alist-cons key value after)))))) +(define-syntax-rule (modify-phases phases mod-spec ...) + "Modify PHASES sequentially as per each MOD-SPEC, which may have one of the +following forms: + + (delete ) + (replace ) + (add-before ) + (add-after ) + +Where every <*-phase-name> is an automatically quoted symbol, and +an expression evaluating to a procedure." + (let* ((phases* phases) + (phases* (%modify-phases phases* mod-spec)) + ...) + phases*)) + +(define-syntax %modify-phases + (syntax-rules (delete replace add-before add-after) + ((_ phases (delete old-phase-name)) + (alist-delete 'old-phase-name phases)) + ((_ phases (replace old-phase-name new-phase)) + (alist-replace 'old-phase-name new-phase phases)) + ((_ phases (add-before old-phase-name new-phase-name new-phase)) + (alist-cons-before 'old-phase-name 'new-phase-name new-phase phases)) + ((_ phases (add-after old-phase-name new-phase-name new-phase)) + (alist-cons-after 'old-phase-name 'new-phase-name new-phase phases)))) + ;;; ;;; Text substitution (aka. sed). -- 2.2.1 --=-=-= Content-Type: text/plain On the other topic, I'm afraid I know yet too little about gexprs and Guix internals... Taylan --=-=-=--