Lambda vs. function

Mark S. Miller erights at google.com
Tue Oct 28 14:00:40 PDT 2008


On Tue, Oct 28, 2008 at 12:39 PM, Brendan Eich <brendan at mozilla.com> wrote:
> On Oct 28, 2008, at 12:18 PM, Maciej Stachowiak wrote:
>
>> On Oct 27, 2008, at 11:28 PM, Breton Slivka wrote:
>>>
>>> I had a go at combining that concept with my object dispatcher
>>> concept, to try and come up with an example of a reasonable transform
>>> of a switch statement to a structure with equivalent function that
>>> uses (mostly) only lambdas and expressions.
>>
>> The object dispatcher is a neat trick but not a correct transform of
>> switch, since switch compares with == rather than by converting to string
>> like property lookup does.
>
> ===, actually.
>
> Another use for Map.


function foo(n) {
  switch (n) {
    case NaN: return 'x';
    case -0: return 'y';
    default: return 'z';
  }
}
foo(NaN) // must yield z
foo(0) // must yield y

Hopefully Map will not reproduce this insanity, and so be too well
behaved to use directly in a desugaring of switch.

-- 
    Cheers,
    --MarkM


More information about the Es-discuss mailing list