develooper Front page | perl.perl6.language | Postings from March 2003

Statement modifiers

Thread Next
Matthijs van Duin
March 10, 2003 02:04
Statement modifiers
Message ID:
Hi all, just dropping in with some thoughts I had while reading the 
archive of this list.  I've tried to search the list but it's difficult 
with perl keywords being common english words and google unable to search 
for punctuation; if the stuff below has already been fully resolved, I'd 
appreciate some pointers to the corresponding messages. :-)

Anyway, let me start by adding to the statistics: I very much like  
method <~ $obj  and  $arg ~> sub  and I like support of Unicode aliases 
for operators as long as plain ascii versions remain available too.

Now the real subject.. has the issue of multiple statement modifiers 
already been settled?  I saw some mention it wasn't going to be supported, 
but also mentions of how it would be useful;  I can think of such a 
situation myself:

.method when MyClass given $obj;
    as alternative to:
$obj.method if $obj.isa(MyClass);

except without duplicating $obj, which may be worthwhile if it's a longer 
expression.  If multiple modifiers are really a no-no, then I think at 
least the conditionals (if, unless, when) could be made lowest-precedence 
right-associative infix operators, and leave the status of "statement 
modifier" for loops and topicalizers.

This would mean that the above would be valid, and also things like:
.. if .. if .. for ..;  But that multiple nested loops would be illegal 
using modifiers and would require a real block.  (which makes some sense, 
since it's hard to think of a construction where multiple loop-modifiers 
would be useful: if you have  ... for @a for @b  then you'd be unable to 
use the @b-element since $_ would be the loop var of the inner loop)

I also think this gives a nice symmetry of various operators that only 
differ in L2R/R2L and precedence (plus the ability to overload ofcourse):

$x and $y               $y if $x
$x or $y                $y unless $x
$x . $y                 $y <~ $x
$x ( $y )               $y ~> $x

Which I personally think is a Good Thing: I like to structure my code to 
put the most important part of a statement on the left and exceptional 
cases and details on the right.  Having multiple operators with different 
precedence (&&, and, if) also helps avoiding lots of parentheses, which I 
think is another Good Thing because they make code look cluttered.  When 
I want visual grouping I prefer to use extra whitespace.  Perhaps it's 
not as maintainable, but it is more readable imho.

Hmmm.. and I just realized.. is something like 'print while <>;' still 
available in perl 6?  And if so, that means the while-loop would 
topicalize in this case?  What would the criterium be for "this case"? (I 
hope not the kludge it is right now in perl 5 ;-)

Matthijs van Duin  --  May the Forth be with you!

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About