[Petal] New syntaxes

Fergal Daly fergal at esatclear.ie
Wed Jul 9 23:27:55 BST 2003


On Wednesday 09 July 2003 20:21, Grant McLean wrote:
> As William suggests, if we could set an option that caused the
> simpler accessor methods to be selected based on the type of arguments
> passed to the first template invocation then we could have the best
> of both worlds - better performance with no syntax change.

Possible but very very messy. You'd have to compile the code with lots of 
extra monitoring code to check what the types were, record that info and then 
recompile the whole thing again based on that. If you ever put different 
types into your data, you'd either get errors or worse still no errors, just 
incorrect results.

At least with the {} and [] syntax you are making a conscious decision. I 
don't really like the current "do the right thing" behaviour because maybe 
Petal's "right thing" is actually the wrong thing. I'd much rather specify 
that x is a method call or y is an array access.

Consider thing/0 where thing is supposed to be an array but due to a bug, it 
comes out as a hash. Currently Petal will give you back $hash->{thing}->{0} 
when you really wanted it to die with an error. Or say type thing/methd when 
I should hve typed thing/method, I'd like Petal to die with an error like 
"there is no methd() method" and I realise aha I misspelled it. Instead Petal 
will notice there is no methd method and so will fall back to hash access and 
I'll get $hash->{thing}->{methd} which is not what I wanted.

It also gives my code a 30% speed boost if I specify everything.

I'm not talking about changing the syntax, the old syntax would still be there 
because it's also useful. I'd just like the option to be there and I think 
using Perl's notation makes sense because it's what we're familiar with,

F



More information about the Petal mailing list