On Thu, 28 Sep 2006 10:18:14 +0900, Alex Gutteridge wrote:

> I'm working on converting a Python module (RPy) to Ruby and am trying  
> to keep the api as close to the original as possible. In Python it  
> (appears - my Python is very weak) that this is valid syntax:
> 
> foo[x](y,z)
> 
> Where 'foo' is an object with attribute 'x' which itself is callable  
> - in this case with the parameters 'y' and 'z'. The 'foo[x]' object  
> is actually an R function and some magic is subsequently performed to  
> convert the parameters and call the function from Python/Ruby.
> 
>  From my experiments it appears that 'foo[x](y,z)' is always a  
> SyntaxError in Ruby and the closest I can get in Ruby syntax to the  
> Python is:
> 
> foo[x][y,z]
> 
> But this isn't quite as pretty, since the distinction between the  
> function ('foo[x]') and the parameters 'y' and 'z' is not as visually  
> obvious.
> 
> foo[x].call(y,z)
> 
> is another option, but goes still further from the Python api. Not a  
> big problem for sure, but I just wanted to make sure there wasn't  
> some magic trick I was missing to make the original Python ('foo[x] 
> (y,z)') also valid Ruby.

foo[x].call(y,z) may be further from the original python syntax, but it's
ruby's standard syntax for doing this, as exemplified by Proc objects and
Method objects. Given the philosophy of duck typing, I don't advise
trying to depart from this convention.

--Ken Bloom

-- 
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/
I've added a signing subkey to my GPG key. Please update your keyring.