Re: Lambda vs. function

2008-10-28 Thread David-Sarah Hopwood
Breton Slivka wrote: [...] var dispatch = { 1: lambda () { p() ? f(), g() : dispatch[2](); }, I'm nitpicking, but this is invalid syntax -- due to the relative precedence of comma and ?:, it will be parsed as: (p() ? f()), (g() : dispatch[2]()); You want something

Re: Lambda vs. function

2008-10-28 Thread Maciej Stachowiak
On Oct 27, 2008, at 11:28 PM, Breton Slivka wrote: I would argue it. You can either equivalently consider the fall through to be a jump, or say it behaves as if the code of case 2 as if the code of case 2 were duplicated into case 1 - Maciej I had a go at combining that concept with my

Re: Lambda vs. function

2008-10-28 Thread Brendan Eich
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

Re: Lambda vs. function

2008-10-28 Thread Peter Michaux
On Mon, Oct 27, 2008 at 2:34 PM, Breton Slivka [EMAIL PROTECTED] wrote: I don't know if anyone will find this relevant or useful, but in my personal code, I have changed over to completely avoiding the switch statement altogether, in favor of primarily using objects with subscript notation.

Re: Lambda vs. function

2008-10-28 Thread Maciej Stachowiak
On Oct 28, 2008, at 12:46 PM, Peter Michaux wrote: I do roughly the same thing. Using an object is faster than switch also, as far as I recall doing some tests. The speed of switch seems to be the same speed as if-else if-else if-...-else. It really depends on what you are doing. At least

Re: Lambda vs. function

2008-10-28 Thread Brendan Eich
On Oct 28, 2008, at 2:00 PM, Mark S. Miller wrote: Hopefully Map will not reproduce this insanity, and so be too well behaved to use directly in a desugaring of switch. I don't propose to desugar switch, but yes: default Map should use identity (eq), not ===. /be

Re: Lambda vs. function

2008-10-27 Thread Dave Herman
Maciej Stachowiak wrote: You could probably define a rigorous transform to apply to a swtich() statement that turns it into a series of if / else clauses (possibly duplicating later cases if there is no break) and apply the usual if rule to that transform to get case statements into the

Re: Lambda vs. function

2008-10-27 Thread Maciej Stachowiak
On Oct 27, 2008, at 6:46 AM, Dave Herman wrote: Maciej Stachowiak wrote: You could probably define a rigorous transform to apply to a swtich() statement that turns it into a series of if / else clauses (possibly duplicating later cases if there is no break) and apply the usual if rule to

Re: Lambda vs. function

2008-10-22 Thread Maciej Stachowiak
On Oct 21, 2008, at 6:14 PM, Waldemar Horwat wrote: Maciej Stachowiak wrote: I don't think you can represent tail position in a switch statement with your attribute grammar notion, but it's clear to me that the statement immediately before a break statement, or else the last statement in

Re: Lambda vs. function

2008-10-21 Thread Maciej Stachowiak
On Oct 20, 2008, at 2:23 PM, Dave Herman wrote: Yes, that's what I was referring to earlier. Do you now understand my mail from 10/17/2008 12:39? You mean these examples? lambda h(x) { switch (x) { case 1: g(); break; case 2: ... } } I doubt there's any clean

Re: Lambda vs. function

2008-10-20 Thread Waldemar Horwat
Dave Herman wrote: Do you see where I'm going with this? It's a pretty natural idea. The branches of an if-statement can be in tail position because they are the last thing produced by the if-statement. Some things like loop forms and switch won't be able to contain tail positions because

Re: Lambda vs. function

2008-10-20 Thread Dave Herman
Yes, that's what I was referring to earlier. Do you now understand my mail from 10/17/2008 12:39? You mean these examples? lambda h(x) { switch (x) { case 1: g(); break; case 2: ... } } I doubt there's any clean way to fit tail positions into a switch

Re: Lambda vs. function

2008-10-17 Thread Waldemar Horwat
Dave Herman wrote: What is your point? To write a recursive factorial I'd write either: lambda f(x) { if (x == 0) 1; else f(x - 1); } or: function f(x) { if (x == 0) return 1; else return f(x - 1); } Right, good, so far we're on the same page. Either one is subject

Re: Lambda vs. function

2008-10-17 Thread Dave Herman
What you appear to be saying is that wrapping the call to g() inside another statement indicates that it will not be tail-recursive. No, that's not what I'm saying-- that's a given and not relevant. What I'm trying to say is that trying to make return into a tail-calling form is clunky

Re: Lambda vs. function

2008-10-17 Thread Dave Herman
No, I must have misunderstood what you meant by wrapping the call to g() inside another statement -- I thought you were referring to wrapping it in a context such as { -- ; stmt; } which would obviously not be a tail position. But this: lambda f(x) { if (x == 0) 1; else f(x -

Lambda vs. function

2008-10-16 Thread Waldemar Horwat
Dave Herman wrote: I don't see enough of a benefit to warrant inclusion of a new lambda concept. It's just another way of doing what local functions can do. As I see it, the major benefits of `lambda' are a) introducing a low-level and compositional primitive that is useful for code

Re: Lambda vs. function

2008-10-16 Thread Dave Herman
b) creating a clearer place in the language syntax to enforce tail calling by eliminating `return' I don't understand what you mean in point b. Consider two different syntaxes for a function performing a tail call: lambda(x) { f(x) } function(x) { return f(x) } The traditional

Re: Lambda vs. function

2008-10-16 Thread Brendan Eich
On Oct 16, 2008, at 1:55 PM, Waldemar Horwat wrote: var: Not an issue if you're not using var inside the lambda. Code generation that wants to use lambda would use var why? arguments: Again, not an issue if you're not using the arguments array. If a code generator is updated for

Re: Lambda vs. function

2008-10-16 Thread Peter Michaux
On Thu, Oct 16, 2008 at 3:04 PM, Brendan Eich [EMAIL PROTECTED] wrote: On Oct 16, 2008, at 1:55 PM, Waldemar Horwat wrote: var: Not an issue if you're not using var inside the lambda. Code generation that wants to use lambda would use var why? arguments: Again, not an issue if you're not

Re: Lambda vs. function

2008-10-16 Thread Waldemar Horwat
Brendan Eich wrote: On Oct 16, 2008, at 1:55 PM, Waldemar Horwat wrote: var: Not an issue if you're not using var inside the lambda. Code generation that wants to use lambda would use var why? arguments: Again, not an issue if you're not using the arguments array. If a code generator

Re: Lambda vs. function

2008-10-16 Thread Waldemar Horwat
Dave Herman wrote: b) creating a clearer place in the language syntax to enforce tail calling by eliminating `return' I don't understand what you mean in point b. Consider two different syntaxes for a function performing a tail call: lambda(x) { f(x) } function(x) { return f(x)