guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/03: monads: Inline the procedure returned by liftN.


From: Ludovic Courtès
Subject: 01/03: monads: Inline the procedure returned by liftN.
Date: Fri, 28 Aug 2015 23:24:31 +0000

civodul pushed a commit to branch master
in repository guix.

commit b6c6105cacf8093bafcdbb73fad591070cfaa8d7
Author: Ludovic Courtès <address@hidden>
Date:   Fri Aug 28 15:17:20 2015 +0200

    monads: Inline the procedure returned by liftN.
    
    * guix/monads.scm (define-lift): Turn into a macro that open-codes the 
result
      of its lift.
---
 guix/monads.scm |   23 ++++++++++++++++++-----
 1 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/guix/monads.scm b/guix/monads.scm
index 2196a9c..61cd533 100644
--- a/guix/monads.scm
+++ b/guix/monads.scm
@@ -225,11 +225,24 @@ CONDITION is true, return *unspecified* in the current 
monad."
 (define-syntax define-lift
   (syntax-rules ()
     ((_ liftn (args ...))
-     (define (liftn proc monad)
-       "Lift PROC to MONAD---i.e., return a monadic function in MONAD."
-       (lambda (args ...)
-         (with-monad monad
-           (return (proc args ...))))))))
+     (define-syntax liftn
+       (lambda (s)
+         "Lift PROC to MONAD---i.e., return a monadic function in MONAD."
+         (syntax-case s ()
+           ((liftn proc monad)
+            ;; Inline the result of lifting PROC, such that 'return' can in
+            ;; turn be open-coded.
+            #'(lambda (args ...)
+                (with-monad monad
+                  (return (proc args ...)))))
+           (id
+            (identifier? #'id)
+            ;; Slow path: Return a closure-returning procedure (we don't
+            ;; guarantee (eq? LIFTN LIFTN), but that's fine.)
+            (lambda (liftn proc monad)
+              (lambda (args ...)
+                (with-monad monad
+                  (return (proc args ...))))))))))))
 
 (define-lift lift0 ())
 (define-lift lift1 (a))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]