sequence function: if
description:
if(ket, seq, seq)
if(ket, seq, seq, seq)
a crude approximation to an if function
NB: it does not work the way you think it does!
For example:
if(some|condition>, branch|a>, branch|b>)
evaluates all sequences: some|condition>, branch|a>, branch|b> before it is even fed to the if function.
This is a big problem if you try to use it for recursion.
But it is possible if you do an extra couple of steps:
process-if if(some|condition>, |a>, |b>)
process-if |a> #=> foo1
process-if |b> #=> foo2
Or:
process-if if(some|condition>, |a:> __ |_self> , |b:> __ |_self>)
process-if |a: *> #=> foo1 remove-leading-category |_self>
process-if |b: *> #=> foo2 remove-leading-category |_self>
3 parameter version:
if(some|condition>, |branch a>, |branch b>, |branch c>)
returns |branch a> if some|condition> is 'true' or 'yes'
returns |branch b> if some|condition> is 'false' or 'no'
returns |branch c> otherwise
examples:
split-num |*> #=> process-if if(is-less-than[1000] |_self>, |less than 1000:> __ |_self>, |greater than 1000:> __ |_self>)
process-if |less than 1000: *> #=> remove-leading-category |_self>
process-if |greater than 1000: *> #=> mod[1000] remove-leading-category |_self> . split-num int-divide-by[1000] remove-leading-category |_self>
split-num |532>
|532>
split-num |12345>
|345> . |12>
split-num |12345678901234567890>
|890> . |567> . |234> . |901> . |678> . |345> . |12>
if(|True>, |a>, |b>, |c>)
|a>
if(|False>, |a>, |b>, |c>)
|b>
if(|>, |a>, |b>, |c>)
|c>
if(|fish>, |a>, |b>, |c>)
|c>
see also:
big-numbers-to-words example
wif, remove-leading-category
Home