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
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
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:
-
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) (*