diff options
author | Leah Neukirchen <leah@vuxu.org> | 2022-10-31 18:05:01 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2022-10-31 18:05:01 +0100 |
commit | 61140713d03ae58ccf933d00153d7ebaad2be762 (patch) | |
tree | 7b5a9296a4be9ebedd0eebe31ef58ff555e269aa | |
parent | 60554dbaea5b76f152999804031796c242735a50 (diff) | |
download | mew-61140713d03ae58ccf933d00153d7ebaad2be762.tar.gz mew-61140713d03ae58ccf933d00153d7ebaad2be762.tar.xz mew-61140713d03ae58ccf933d00153d7ebaad2be762.zip |
add op*
-rw-r--r-- | mew.scm | 15 | ||||
-rw-r--r-- | mew.svnwiki | 12 |
2 files changed, 27 insertions, 0 deletions
diff --git a/mew.scm b/mew.scm index 70edbdd..7d9d2ac 100644 --- a/mew.scm +++ b/mew.scm @@ -23,6 +23,7 @@ <>? ~?) + (import-for-syntax srfi-1) (import-for-syntax matchable) (import scheme @@ -172,6 +173,20 @@ ((_ x) `(,(rename 'lambda) ... ,x)) ((_ . rest) `(,(rename 'lambda) (_) ,rest)))))) + (define-syntax op* + (er-macro-transformer + (lambda (expr rename compare) + (when (= 1 (length expr)) + (syntax-error "op* needs at least one argument")) + `(,(rename 'lambda) ... + ,(receive (pre post) (break (lambda (x) (compare '... x)) (cdr expr)) + (match post + (() `(,(rename apply) ,@pre ...)) + ((x) `(,(rename apply) ,@pre ...)) + ((x . y) `(,(rename apply) ,@pre + (,(rename append) ... (,(rename list) ,@y)))) + )))))) + (define-syntax rep (syntax-rules () ((_ name ((var val) ...) body ...) diff --git a/mew.svnwiki b/mew.svnwiki index 49831a9..c3c03c7 100644 --- a/mew.svnwiki +++ b/mew.svnwiki @@ -117,6 +117,18 @@ If {{<form>>} is empty, behaves as {{values}}, i.e. the identity function. {{(op + 2 _)}} is the function that adds 2 to its argument. +<syntax>(op* <form>)</syntax> + +Returns a procedure that evaluates {{<form>}} with {{...}} expanded +to all its arguments. {{...}} must only appear once and must not +be nested further. If {{...} does not appear in {{<form>}}, it's +added implicitly at the end. + +{{(op* + 5)}} is the function that adds 5 and then all its arguments. + +{{(op* - 0 ... 2)}} is the function that subtracts all its arguments from 0 +and finally 2. + <procedure>(negate <fun>)</procedure> Alias for {{complement}}. |