Re: Closures versus objects

Justin Sheehy <[email protected]>
Newsgroups gmane.comp.lang.lightweight
Message-ID <[email protected]>
Mike,

I will read and respond to your mail in more detail later, but here  
is an easy part to answer:

On Feb 15, 2007, at 2:13 PM, Mike Newhall wrote:

> there's no reason a language couldn't be designed to allow objects  
> to be invoked in a way semantically identical to functions  
> (ignoring CLOS generics for the moment, surely some OO languages  
> already do this; Python?  JavaScript?), invoking some default method.

You are correct.  In Python, any object with a __call__ method  
defined is callable in exactly the same way as a function.

 >>> class Foo:
...  def __call__(self, x): return 'foo %s' % x
...
 >>> f = Foo()
 >>> f("bar")
'foo bar'

-Justin
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.