|(require my-cond)||package: my-cond|
source code: https://github.com/AlexKnauth/my-cond
(my-cond my-cond-clause ...)
my-cond-clause = normal-cond-clause | for/cond-clause-form | for*/cond-clause-form | (cond-expander-id stuff ...) | cond-expander-id stuff ... | #:def def | #:defs [def ...] | #:let ([var val] ...) | #:begin [def-or-expr ...] normal-cond-clause = [condition-expr then-body ...+] | [else then-body ...+] | [condition-expr => proc-expr] | [condition-expr] for/cond-clause-form = (for/cond-clause (for-clause ...) my-cond-clause ...) for*/cond-clause-form = (for*/cond-clause (for-clause ...) my-cond-clause ...) for-clause = [id seqence-expr] | [(id ...) sequence-expr] | #:when guard-expr | #:unless guard-expr | #:break guard-expr | #:final guard-expr
As soon as one of the conditions evaluates to a true value, it returns whatever cond would return as the result of that clause.
Otherwise, it goes on to the next clause, if there is one.
If there is no "next iteration," then it goes on to the next clause after the for/cond-clause form (if there is one).
> (require my-cond)
> (my-cond (for/cond-clause ([i (in-range 0 5)]) [(<= 3 i) i] [(<= 2 i) (number->string i)]))
> (my-cond (for/cond-clause ([i (in-range 0 5)]) [(<= 2 i) i] [(<= 3 i) (number->string i)]))
(for/cond-clause (for-clause ...) my-cond-clause ...)
(for*/cond-clause (for-clause ...) my-cond-clause ...)
> (require my-cond racket/match (for-syntax racket/base))
> (define-syntax $m (cond-expander (syntax-rules () [(my-cond [$m val pat body ...] clause ...) (match val [pat body ...] [_ (my-cond clause ...)])]))) > (define x '(1 2 3))
> (my-cond [$m x (list a b c) (+ a b c)] [else #f])
> (my-cond [$m 5 (list a b c) (+ a b c)] [else #f])