|
|
On Fri, 15 Aug 2008 08:58:35 +0100, Invisible wrote:
> Nicolas Alvarez wrote:
>
>> JavaScript functions don't need names.
>>
>> var value = (function (x) {
>> return 3*x + 5;
>> })(42);
>>
>> That actually works.
>
> Ooo... that's interesting.
Python:
value = (lambda(x): 3*x+5)(42)
Lua:
value = (function(x) return 3*x+5 end)(42)
Ruby (1):
def test
yield 42
end
value = test { |x| 3*x+5 }
Ruby (2):
value = lambda { |x| 3*x+5 } .call(42)
C++0x:
int main()
{
int value = <>(int x) (3*x+5) (42);
}
(I would have tested this, but the build instructions
at http://parasol.tamu.edu/groups/pttlgroup/lambda/
don't work for me, tried to computers...)
i386 assembly (ok, this is cheating):
mov eax, 42
call over
lea eax, [eax*2+eax+5]
ret
over:
pop eax
call eax
mov [value], eax
--
Joel Yliluoma - http://iki.fi/bisqwit/
Post a reply to this message
|
|