diff options
author | Leah Neukirchen <leah@vuxu.org> | 2022-10-14 20:53:39 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2022-10-14 20:53:39 +0200 |
commit | 816514bf9e2734d43877c6011ec9dc00fb5cee2f (patch) | |
tree | 7cdfaefc501074868f0b6b59247f960ccc0d9849 | |
parent | 06e8b1a04e316161cc8146be470380802d243eeb (diff) | |
download | mew-816514bf9e2734d43877c6011ec9dc00fb5cee2f.tar.gz mew-816514bf9e2734d43877c6011ec9dc00fb5cee2f.tar.xz mew-816514bf9e2734d43877c6011ec9dc00fb5cee2f.zip |
add set->, set->>
-rw-r--r-- | mew.scm | 22 | ||||
-rw-r--r-- | mew.svnwiki | 5 |
2 files changed, 25 insertions, 2 deletions
diff --git a/mew.scm b/mew.scm index 8615074..9242947 100644 --- a/mew.scm +++ b/mew.scm @@ -14,11 +14,11 @@ prn puts rep str slurp - tbl + tbl time while until vals - -> ->> fun-> fun->> + -> ->> fun-> fun->> set-> set->> ~?) (import-for-syntax matchable) @@ -313,6 +313,24 @@ ((_ rest ...) (lambda (x) (->> x ->> rest ...))))) + (define-syntax set-> + (syntax-rules (-> ->>) + ((_ location -> rest ...) + (set! location (-> location -> rest ...))) + ((_ location ->> rest ...) + (set! location (-> location ->> rest ...))) + ((_ location rest ...) + (set! location (-> location -> rest ...))))) + + (define-syntax set->> + (syntax-rules (-> ->>) + ((_ location -> rest ...) + (set! location (->> location -> rest ...))) + ((_ location ->> rest ...) + (set! location (->> location ->> rest ...))) + ((_ location rest ...) + (set! location (->> location ->> rest ...))))) + (def (~? str pat) (let ((data (irregex-search pat str))) (if data diff --git a/mew.svnwiki b/mew.svnwiki index 967c939..863bccf 100644 --- a/mew.svnwiki +++ b/mew.svnwiki @@ -254,3 +254,8 @@ Nesting lambdas: like {{->}} but the nesting starts with the argument of the lambda. {{(fun-> b c -> d e f)}} expands to {{(lambda (x) (-> x -> b c -> d e f))}}. {{(fun->> b c ->> d e f)}} expands to {{(lambda (x) (->> x ->> b c ->> d e f))}}. + +<syntax>(set-> loc -> ...)</syntax> +<syntax>(set->> loc ->> ...)</syntax> + +Mutation with nesting macros: shortcut for {{(set loc (-> loc ...))}}. |