News for hackers. Stuff that matters.
Re:False Cognates and Syntax: The Importance of Syntax in Pr... by babarock on Tuesday May 29, 2012 @07:45AM (#4036983)
You can do something similar in any language that support booleans as keys for dictionaries/hashtables/maps/associative arrays/...

For instance in Lua:

    function abs(x)
        test = {
           [true]=-x,
           [x>0]=x,
           [x==0]=0}
        return test[true]
    end

    > print (abs(-3))
    3
To understand this code, think that `test[true]` is overwritten at initialization time by the last predicate to evaluate to True.

It's not the best way to do this, but maybe it'will help understand the above construct.

Re:False Cognates and Syntax: The Importance of Syntax in Pr... by reycharles on Tuesday May 29, 2012 @07:57AM (#4037025)
There's a difference, though. This example evaluates every "branch".
Re:False Cognates and Syntax: The Importance of Syntax in Pr... by reikonomusha on Tuesday May 29, 2012 @10:14AM (#4037540)
Make it even more ridiculous and wrap every branch in a lambda function, then do

    test[true]()
Re:False Cognates and Syntax: The Importance of Syntax in Pr... by mahcuz on Tuesday May 29, 2012 @10:35AM (#4037629)
That would only evaluate the original [true] key, though, right?
Re:False Cognates and Syntax: The Importance of Syntax in Pr... by tgasson on Tuesday May 29, 2012 @10:51AM (#4037711)
No, `test[true]` will be reassigned to the given function each time the condition evaluates to true. Calling `test[true]()` will execute that given function.