On Thu, Feb 07, 2002 at 03:15:49PM +0000, Richard Clamp wrote:
> On my current project, we've noticed, at quite an annoying time, that
> the fat comma (=>) is treated differently than we initially expected
> for calling methods.

It's a feature.

The idea being that you can have positional arguments and named arguments
and TT recognises the difference and bundles all the named params into 
a hash for you.

>  foo.bar(foo => 'bar') gets magically mutated into { foo => 'bar' }
>  foo.bar('foo', 'bar') passes two elements, ( 'foo', 'bar' )

   foo.bar('foo', x => 'y', 'bar', wiz => 'waz') 
       => ('foo', 'bar', { x => 'y', wiz => 'waz' })

In TTsville, it's important to have a distinction between positional and
named arguments (although I must admit I'm hard pressed to think of the 
Very Good Reason right now).  There was no precedent for named params
in Perl so I had to set one.  I chose to bundle all named params 
together and pass them by hash ref as the last argument.

> Which surprised me, as I was expecting the more perlish (foo => 'bar')
> becomes ('foo', 'bar'), and so were the methods we'd written.

TT treats both '=' and '=>' equally and I tend to use the former so as
not to confuse myself into a Perl way of thinking.  

e.g.

  foo.bar(foo='bar')

I admit it can be confusing if you're expecting '=>' to behave like it
does in Perl, but I suppose my justification is that TT isn't Perl (except
when it wants to be) :-)

> Is this intended, or just an implementation feature of the => operator
> in TT?  Also, is there an easy way to switch the behaviour to what I
> was expecting.

It happens in the parser.  You could subclass/hack the parser to behave
more Perl-like but then you might find it made other things blow up that
expect that behaviour.

For more info, it's documented here:
http://tt2.org/docs/leon/Manual/Variables.html#Parameters_and_Return_Values

HTH
A



Reply via email to