COND statement added
Brian Rice
water at tunes.org
Wed Mar 15 21:45:30 PST 2006
I've added conditions: and conditions:otherwise: to complement
caseOf: and caseOf:otherwise: to src/lib/sequence.slate. Basically
this is a Lisp-style COND statement, where:
conditions:
{[testBlock] -> [actionBlock].
...} otherwise: [failOverBlock].
Will run the testBlock's in turn, and execute the first actionBlock
associated with a True-result. It'll return the result of that
actionBlock and not evaluate further. If no testBlock returns True,
the failOverBlock is run and its result returned.
There is no byte-compiler optimization for this, but there
conceivably could be, as long as all the blocks are given literally
(i.e. in brackets). There's a sketchy version of this that will be
uploaded shortly but it has to do extra work whereas caseOf: has a
special bytecode to quickly check lots of literals.
Note of course that Slate's dispatch system and the use of dynamic
mixins in conjunction can do via polymorphism most of what this idiom
can do, so it really shouldn't show up much. However, it'd help in
identifying places where better dispatch algorithms (pattern-matching
or predicate dispatch) would specifically help.
--
-Brian
http://tunes.org/~water/brice.vcf
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : /archives/slate/attachments/20060315/bbf179fa/PGP.pgp
More information about the Slate
mailing list