2 ms·
Are you familiar with python? Perhaps this will help: if cnd: return do_big_stuff else: return do_other_big_stuff has different semantics
by geocar 16y ago
Are you familiar with python? Perhaps this will help:
if cnd:
return do_big_stuff
else:
return do_other_big_stuff
has different semantics than a hypothetical "if" function call:
def a():
return do_big_stuff
def b():
return do_other_big_stuff
return if(cnd,a(),b())
Note here, both "do_big_stuff" and "do_other_big_stuff" are evaluated, regardless of the value of "cond".
A short-circuiting if (only possible if "if" is a special form) will ONLY evaluate a() (and thus "do_big_stuff") if "cond" returns a truth-value.
Now, Factor's "if" works like this (in python):
return if(cnd,a,b)()
That's fine- and it still has the short-circuiting semantics, but there's still a question of taste here.
- Avshalom 16y agoYeah okay I got it. I think the funcall/lambda stuff got me confused, it's kind of obvious in hindsight. In which case I agree it's a matter of taste. I guess I just like the taste of Factor/REBOL always passing blocks to if, having to say t [ 0 ] [ 3 ] if instead of simply say t 0 3 if is the trade off I suppose[1]. I'm guessing it works for picolisp because it's purely interpreted? because it certainly doesn't seem to be passing lambdas to 'if'. Can anyone confirm/deny? [1]well actually the word ? does that but to make it work for both you need to do: : myif ( ? true false -- ) ? dup quotation? [ call ] [ ] if ; inline
- geocar 16y agoIt works in picolisp because the author foolishly implemented FEXPRs instead of special forms, and rather than fix this problem, spends time trying to convince people that this is actually a feature, and that it offers a certain succinctness that can't be achieved in other ways.