diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-05-14 11:01:44 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-05-14 11:01:44 +0200 |
commit | f83f3ea71a897428902d78b217b207b62e7ad8d2 (patch) | |
tree | abc968e35f048520d9da50fb6b1b6e5849dd9417 /module | |
parent | RRule Limiters works much better. (diff) | |
download | calp-f83f3ea71a897428902d78b217b207b62e7ad8d2.tar.gz calp-f83f3ea71a897428902d78b217b207b62e7ad8d2.tar.xz |
Add label macro.
Diffstat (limited to '')
-rw-r--r-- | module/util.scm | 19 |
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" |