diff --git a/d-.scm b/d-.scm index a1baea3..2a19ec1 100644 --- a/d-.scm +++ b/d-.scm @@ -3,6 +3,8 @@ #:export (~> ~>> + if-not + when-not partial argmin)) @@ -18,6 +20,12 @@ [(_ v (fn args ...) more ...) (~> (fn args ... v) more ...)] [(_ v fn more ...) (~> (fn v) more ...)])) +(define-syntax-rule (if-not pred body ...) + (if (not pred) body ...)) + +(define-syntax-rule (when-not pred body ...) + (when (not pred) body ...)) + (define (partial fn . args) (lambda x (apply fn (append args x)))) diff --git a/test.scm b/test.scm index 4f91c28..2762241 100644 --- a/test.scm +++ b/test.scm @@ -23,6 +23,15 @@ (define value (~>> 1 (/ 2) (/ 2))) (assert (= value 1)))) +(define-test if-not + (assert (eq? (if-not #f 'a 'b) 'a))) + +(define-test when-not + (positive-case + (assert (eq? (when-not #f 'do-some-stuff 'return) 'return))) + (negative-case + (assert (unspecified? (when-not #t 'do-some-stuff 'return))))) + (define-test partial (test (define value (partial / 2))