diff options
author | Hugo Hörnquist <hugo@hornquist.se> | 2020-01-23 14:00:12 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@hornquist.se> | 2020-01-23 14:00:12 +0100 |
commit | 307e290aaf8aa2f252ebfa98fe25604751580967 (patch) | |
tree | 50365116423421d666dfd3bc9425a27a691380d1 /module/util | |
parent | Allow user supplied description filters. (diff) | |
download | calp-307e290aaf8aa2f252ebfa98fe25604751580967.tar.gz calp-307e290aaf8aa2f252ebfa98fe25604751580967.tar.xz |
Add case* and define-many.
Diffstat (limited to '')
-rw-r--r-- | module/util.scm | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/module/util.scm b/module/util.scm index 31fd9997..4cc591ab 100644 --- a/module/util.scm +++ b/module/util.scm @@ -13,7 +13,9 @@ re-export-modules use-modules* -> set set-> aif awhen - tree-map let-lazy let-env) + tree-map let-lazy let-env + case* define-many + ) #:replace (let* set! define-syntax when unless if)) @@ -187,6 +189,13 @@ +;; Like `case', but evals the case parameters +(define-syntax case* + (syntax-rules (else) + [(_ invalue ((value ...) body ...) ...) + (cond ((memv invalue (list value ...)) + body ...) + ...)])) ;; Allow set to work on multiple values at once, ;; similar to Common Lisp's @var{setf} @@ -242,6 +251,13 @@ (set/r! ffield (fproc ffield)))))) +(define-syntax define-many + (syntax-rules () + [(_) (begin)] + [(_ (symbols ...) value rest ...) + (begin (define symbols value) ... + (define-many rest ...))])) + ;; 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" @@ -374,7 +390,7 @@ ;; operator is used. (define-syntax set (syntax-rules (=) - [(set (acc obj) value) + [(set (acc obj) value) (set-fields obj ((acc) value))] [(set (acc obj) = (op rest ...)) |