Simon Cozens wrote:
> Once again we're getting steadily closer to inventing Ruby.

Agreed, but I don't think this is necessarily a Bad Thing.

Larry said ~~ "People have been borrowing ideas from Perl for a long time,
now it's time to borrow some back".

I like Ruby, I like dot ops, and I like being able to chain them together
from left to right.  I would really like it if these were some of the 
ideas that we borrow back from Ruby (and other places).

As it happens, I've already borrowed them for the Template Toolkit.
Of course, TT doesn't count as a Real Programming Language, but it 
does support the same syntax for accessing data and it's very useful.

  myhash.keys.sort.join(', ')     # valid in both Ruby and TT 

Of course, this is semantically no different to the Perl 5 equivalent:

  join(', ', sort keys %$myhash)

but I find it easier to read as it progresses more naturally, to me at 
least, from left to right.  Take myhash, get the keys, sort them, then 
join them together.  

This is essentially a pipeline style of processing:
 
   a --> b --> c

whereas the usual right to left is technically a nested form:

   a ( b ( c ) )

which effectively reverses the order of evaluation of the pipeline:

   c --> b --> a

I think both are equally valid and should be supported, if possible.

Sometimes it makes sense to think about a problem from start to finish
(input driven or "push").  Other times it's better to think about the 
desired goal and work backwards towards the beginning (output driven
or "pull").

In one situation you might think "I want to take myhash, extract the 
keys, sort them and then join them together to make a string" and 
write C<$myhash.keys.sort.join(', ')>.  In another you'll think
"I need a string containing the sorted keys of myhash" and instead
write C<join(', ', sort keys %$myhash)>.

It seems to me that L.R syntax falls out naturally in Perl 6 from the 
dotop.  Hash objects will have 'keys' methods, Array objects will have 
'sort' and 'join' methods and everything should just work as expected.

   $hash.keys.sort.join(', ');

The sticky issue is how to pass a block to sort, map, grep, etc. 

Well, if we can't come up with anything better than explicitly passing 
a block as an argument, e.g.

   $hash.keys.sort({ ... }).join(', ');

then I still think this is better than nothing at all.  

If you end up writing pathological cases where you're passing lots of 
blocks as arguments, then perhaps it would be better written in a regular 
Perl 5 right to left (nested), or even a mixed style.

   join( ', ', sort { ... } $hash.keys );

If we can come up with something that makes this syntactic pill a little
easier to swallow, then that's great.  But even if we can't, I don't think 
it's the end of the world, or even the world.end  :-)


A

Reply via email to