aboutsummaryrefslogtreecommitdiff
path: root/module/util.scm
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--module/util.scm19
1 files changed, 18 insertions, 1 deletions
diff --git a/module/util.scm b/module/util.scm
index 0417d36f..10e36d4e 100644
--- a/module/util.scm
+++ b/module/util.scm
@@ -14,7 +14,7 @@
-> ->> set set-> aif awhen
tree-map let-lazy let-env
case* define-many
- and=>>
+ and=>> label
print-and-return
)
#:replace (let* set! define-syntax
@@ -256,6 +256,23 @@
(begin (def symbols value) ...
(define-many def rest ...))]))
+;; Attach a label to a function, allowing it to call itself
+;; without actually giving it a name (can also be thought
+;; of as letrec-1).
+;; @example
+;; ((label fact
+;; (match-lambda
+;; [0 1]
+;; [x (* x (fact (1- x)))]))
+;; 5)
+;; @end example
+(define-syntax label
+ (syntax-rules ()
+ [(_ self proc)
+ (letrec ((self proc))
+ proc)]))
+
+
;; This function borrowed from web-ics (calendar util)
(define* (sort* items comperator #:optional (get identity))
"A sort function more in line with how python's sorted works"