Thanks Joel, I think this is just what I need. I don't think pif is a good name for it, though, it reminds me of obscure unix commands, not very rebolish. But what is a good name? Perhaps something like "reselect" (because it's a bit like a select reduce, but since that's not strictly true, then that could confuse more..) ? How about "any-select" ? (Guh, same problem) Here's some ideas: http://thesaurus.reference.com/search?q=select
- satisfy, select-if, do-elect ... I don't think there is a good word. - poly-if <- that is my favourite so far. Anton. > Hi, Anton, > > Set the WayBack machine to 2000... ;-) > > Anton Rolls wrote: > > I yearn (want), occasionally, a kind of any/switch-like > > flow-control function... > > Some years ago we had a long discussion about generalizing IF on the > list, and kicked around various options/versions. The copy I could > lay my hands on most quickly was Ladislav's refinement (the last in > the discussion???): > > pif: func [[throw catch] args [block!] /local res] [ > either unset? first res: do/next args [ > if not empty? args [ > throw make error! [script no-arg pif condition] > ] > ][ > either first res [ > either block? first res: do/next second res [ > do first res > ][ > throw make error! [ > script expect-arg pif block [block!] > ] > ] > ][ > pif second do/next second res > ] > ] > ] > > PIF (Polymorphic IF) takes a block of guard-expression/block > pairs and uses the (first true) guard-expressions to select > block to be evaluated. It can be used (I believe) essentially > as you were asking. > > Refactoring PIF to iterative form is left as an exercise for > the reader! ;-) As long as the argument block isn't too long > the recursion likely won't be a problem. > > Heres a sample usage: > > describe: func [x [integer!] y [integer!]] [ > pif [ > x = 1 ["X is one"] > y = 1 ["Y is one"] > x = 2 ["X is two"] > y = 2 ["Y is two"] > true ["X and Y are too big!"] > ] > ] > > which behaves as: > > >> describe 1 1 > == "X is one" > >> describe 2 1 > == "Y is one" > >> describe 2 2 > == "X is two" > >> describe 3 2 > == "Y is two" > >> describe 3 3 > == "X and Y are too big!" > > -jn- > > -- > ---------------------------------------------------------------------- > Joel Neely joelDOTneelyATfedexDOTcom 901-263-4446 -- To unsubscribe from this list, just send an email to [EMAIL PROTECTED] with unsubscribe as the subject.