On Thu, Feb 07, 2002 at 03:42:32PM +0000, Andy Wardley wrote:
> 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.

I feared it might be :)

>    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).

Back in my brain, I either have named parameters or positional ones,
and crossing the streams is still considered bad.

Tell a lie, sometimes I care about what order my named parameters came
in too, but only in corner cases:
  foo->search( colour => 'red', price => 'cheap' ) # redness is more important
  foo->search( price => 'cheap', colour => 'red' ) # cheapness ""

And then I'll normally pass lists more like so
  foo->search(criterion => [{ colour => 'red' }, { price => 'cheap' }])

Whoops, digression.

>                               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.

With hindsight I might be tempted to turn them into instances of some
parameter class, which stringified to their values, and leave them in
place.  That's more reversible given this pathological case:
  foo.bar(tweak => foo, bar, baz) # tweak is the operation

Anyway, how should your method behave when this happens
 [% data = { corner => 'case' }; foo.bar( some, data ) %]

It seems to me that hijinks ensue, as $_[-1] is a hash.  Maybe tt
needs to raise a flag indicating that it's currently calling something
using named parameters, but that's a bit cheesy.

> 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.

Hmm, may take a look at it tomorrow.  Being completely unaware of it's
internals, would it be doable for me to hack in lexical control of the
behaviour, so I could bully something like this into doing what I
mean:

[% PERLISH_ARGS = 1; foo.bar(foo => 'bar') %]

Hopefully keeping it lexical would restrict the breaking of other
things to a light bruising.

-- 
Richard Clamp <[EMAIL PROTECTED]>


Reply via email to