From: Mike Stok Date: 2001-11-30T07:42:08+09:00 Subject: [ruby-talk:26986] Re: first class functions in Ruby On Fri, 30 Nov 2001, MikkelFJ wrote: > In the thread on language design, I mentioned a wish for functions as first > class values. > > I hope someone knowing Ruby deeper than I will follow up on this. > > I'd like to be able to write a function that I can pass as argument to a > Ruby message or to another function. A function is a new concept in Ruby > context. [...] > improved syntax: > > > fun squareFunction arg > arg + arg > end > def aMessage f > f(42) + f(27) > end > def main > aMessage squareFunction > end > What about using a Proc object? def aMessage(f) f.call(42) + f.call(27) end squareFunction = Proc.new { |arg| arg * arg } puts(aMessage(squareFunction)) Mike -- mike@stok.co.uk | The "`Stok' disclaimers" apply. http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA mike@starnix.com | Fingerprint 0570 71CD 6790 7C28 3D60 http://www.starnix.com/ | 75D2 9EC4 C1C0 0599 13DA