|
|
Joel Yliluoma wrote:
> 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);
> }
>
> 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
Haskell [is that cheating??]
value = (\x -> 3*x + 5) 42
Lambda calculus:
\i ->
(\n -> \m -> \f -> \x -> n f (m f x))
(
(\n -> \m -> \f -> \x -> n (m f) x)
(\f -> \x -> f (f (f x)))
i
)
(\f -> \x -> f (f (f (f (f x)))))
[I can't be bothered to write "42" in the lambda calculus. Suffice it to
say it contains 42 copies of the letter "f".]
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|