[racket] Cond function with test-expr = then-body works but is it wise?

2013-05-24 Thread Don Green
It is possible to create a cond test-expr that also serves as the then-body, however, this means that the expression would be executed twice. This seems to be ill advised in principle. Question: If it is ill-advised to create a cond test-expression that also serves as the then body, then what

Re: [racket] Cond function with test-expr = then-body works but is it wise?

2013-05-24 Thread Matthias Felleisen
Would (cond [testing = values] ...) work for you? That returns the value of the testing expression w/o evaluating it twice. On May 24, 2013, at 12:08 PM, Don Green wrote: It is possible to create a cond test-expr that also serves as the then-body, however, this means that

Re: [racket] Cond function with test-expr = then-body works but is it wise?

2013-05-24 Thread Eli Barzilay
10 minutes ago, Don Green wrote: It is possible to create a cond test-expr that also serves as the then-body, however, this means that the expression would be executed twice. This seems to be ill advised in principle. `cond' can have one-expression clauses that serve both purposes: -

Re: [racket] Cond function with test-expr = then-body works but is it wise?

2013-05-24 Thread Laurent
Just for fun, if you have to use the value of the tests in several bodies, you may also define your own macro: #lang racket (define-syntax-rule (cond/let id [test body ...] ...) (cond [test = (λ(id) body ...)] ...)) (let ([x 123a #;123]) (cond/let y [(string-number x) (*