From: Paul Brannan Date: 2001-11-30T07:29:00+09:00 Subject: [ruby-talk:26980] Re: thoughts on virtual base classes, interfaces On Fri, Nov 30, 2001 at 07:15:28AM +0900, MikkelFJ wrote: > The above problem is exactly what would elegantly be handled by first class > functions. You'd just pass the run function directly instead of having to > create an object that respond to some named function like "run". If more > functions that run were desired, it might be better to create a class, or a > list of functions could be passed in a hashtable. In Ruby, I can do this: def foo(fun) fun.call() end def bar() puts "foo!" end foo(Object.method(:bar)) #=> foo! Or, I can do this: x = 42 foo proc { puts x } #=> 42 The problem is not that Ruby does not have first-class functions, but that Ruby makes a distinction between a method and a callable object. IMO, this is not really a problem at all, but actually provides clarity (I've been bitten many times in Python by writing x = foo instead of x = foo()). On a side note, you can do similar things in C++ with the "lambda library" (http://lambda.cs.utu.fi/). I've never used it, but it looks pretty cool. Paul