From e64cd9e4524440e29dda141693fbadd99d20e4fd Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Sat, 22 Oct 2022 18:11:52 +0200 Subject: add given --- mew.scm | 19 ++++++++++++++++++- mew.svnwiki | 6 ++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/mew.scm b/mew.scm index 6ee7924..83aeef8 100644 --- a/mew.scm +++ b/mew.scm @@ -4,7 +4,7 @@ dec def div empty? eof esc fin final for generic-for-each - get gen genumerate gfix giterate gmatch gsplit gwindow + get gen genumerate gfix given giterate gmatch gsplit gwindow inc into keys len loc @@ -346,6 +346,23 @@ ((_ location rest ...) (set! location (->> location ->> rest ...))))) + (define-syntax given + (syntax-rules () + ((_ expr bool (then . then-rest) (else . else-rest)) + (let ((val expr)) + (if bool + (then val . then-rest) + (else val . else-rest)))) + ((_ expr bool (then . then-rest) else) + (given expr bool (then . then-rest) (else))) + ((_ expr bool then (else . else-rest)) + (given expr bool (then) (else . else-rest))) + ((_ expr bool then else) + (given expr bool (then) (else))) + ((_ expr bool then) + (given expr bool then ((op)))) + )) + (define (~? str pat) (let ((data (irregex-search pat str))) (if data diff --git a/mew.svnwiki b/mew.svnwiki index b65d38f..5984123 100644 --- a/mew.svnwiki +++ b/mew.svnwiki @@ -274,3 +274,9 @@ of the lambda. (set->> loc ->> ...) Mutation with nesting macros: shortcut for {{(set loc (-> loc ...))}}. + +(given ?) + +Evaluate {{}}. Then, when {{}} is truthy, behaves like +{{(-> -> }}, otherwise like {{(-> -> )}} +(or just {{}} if no {{}} was passed). -- cgit 1.4.1