aboutsummaryrefslogtreecommitdiff
path: root/module/util.scm
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-05-14 11:01:44 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2020-05-14 11:01:44 +0200
commitf83f3ea71a897428902d78b217b207b62e7ad8d2 (patch)
treeabc968e35f048520d9da50fb6b1b6e5849dd9417 /module/util.scm
parentRRule Limiters works much better. (diff)
downloadcalp-f83f3ea71a897428902d78b217b207b62e7ad8d2.tar.gz
calp-f83f3ea71a897428902d78b217b207b62e7ad8d2.tar.xz
Add label macro.
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"