From: Robert Klemme Date: 2004-06-28T22:43:08+09:00 Subject: Re: (oddity) applying objects with #call() implicitly "gabriele renzi" schrieb im Newsbeitrag news:2o20e09v6gfu8j9isbc62peu4dtfevli1p@4ax.com... > il Mon, 28 Jun 2004 13:37:21 +0200, "Robert Klemme" > ha scritto:: > > > > >> I was going to ask if we could have this: > >> callable arg1,arg2 # implicitly looks for #call > >> callable # the callable object > >> callable() # forces application with zero arguments > >> ... > >> > >> what's wrong with this? > > > >Ambiguity. "callable arg1,arg2" denotes an invocation of the method > >"callable" of "self". "callable()" also invokes the same method albeit > >without arguments. > > well, but ambiguity exists anyway, just think of : > > print p > > "p" may stand for self#p, or a local variable named "p". True. It might be inconsistency then, because for a method "foo" and "foo()" are identical (apart from, that the latter form does not have the ambiguity) but you proposed change would introduce a significant difference between "foo" and "foo()". You probably guessed that I don't like this very much. :-) Well, there are also reasons: ruby could no longer determine at compile time the semantics of this code: def foo(x) x("bar") end Because x("bar") could be a method invocation or it could be an invocation of the Proc instance x. And since we don't have type declarations in Ruby you couldn't get this to work. That's especially true because when foo is defined there need not be a method x at all. (Dunno whether that was clear enough - I'm still sorting this out...) > More, using a method passed in via argument won't be different from > defining a new one in the current scope explicitly (actually, a method > def in a method ends up in the self scope), I mean: it's up to the > user to be smart enough, writing something like: > > def comb(fun1,fun2) > > instead of > def comb(print,puts) > > >However, you can use #[] like this: > > yes, I know, but using #[] is somewhat even worst than #call. > > It is better because it looks like () yet it's worst because it just > mimics something hiding it's meaning, Could you elaborate that? I don't get the point. My understanding was, that you were looking for a nicer more intuitive syntax to invoke a Proc instance. > whereas #call at least is > explicit. That's true. I don't have a problem with #call. :-) Kind regards robert