my-cond
1 my-cond
my-cond
for/  cond-clause
for*/  cond-clause
2 cond-expanders
cond-expander
prop:  cond-expander
cond-expander?
syntax-local-cond-introduce
6.3.90.900

my-cond

 (require my-cond) package: my-cond

source code: https://github.com/AlexKnauth/my-cond

1 my-cond

syntax

(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
like cond, but with the ability to use things like for/cond-clause to iterate through cond-clauses like for would. It does this using cond-expanders.

my-cond also allows easy internal definitions with things like #:defs [def ...] and #:let ([var val] ...).

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 it reaches the end of a my-cond expression where none of the conditions returned a true value, the my-cond expression returns #<void>.

If it reaches the end of a for/cond-clause or for*/cond-clause form, then it goes through the for/cond-clause form again for the next iteration (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).

An else clause can only appear as the last clause of a my-cond (or cond) form, and cannot appear inside of a for/cond-clause or for*/cond-clause form.

Examples:
> (require my-cond)
> (my-cond (for/cond-clause ([i (in-range 0 5)])
             [(<= 3 i) i]
             [(<= 2 i) (number->string i)]))

"2"

> (my-cond (for/cond-clause ([i (in-range 0 5)])
             [(<= 2 i) i]
             [(<= 3 i) (number->string i)]))

2

syntax

(for/cond-clause (for-clause ...) my-cond-clause ...)

syntax

(for*/cond-clause (for-clause ...) my-cond-clause ...)

these are defined as cond-expanders.

2 cond-expanders

procedure

(cond-expander proc)  cond-expander?

  proc : (syntax? . -> . syntax)
returns a cond-expander that uses proc to transform the my-cond form.

Examples:
> (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])

6

> (my-cond [$m 5 (list a b c) (+ a b c)]
           [else #f])

#f

a struct-type property for cond-expanders.

procedure

(cond-expander? v)  boolean?

  v : any/c
returns #t if v is a cond-expander created by cond-expander or prop:cond-expander, returns #f otherwise.

procedure

(syntax-local-cond-introduce stx)  syntax?

  stx : syntax?