Luke Palmer wrote:
Austin Hasting writes:My problem with this is one of abstraction. P6 is, in a lot of places, a giant step forward in terms of abstracting away 'well-understood' operations. Grammar/Regex is one example, properties another.
How do I concisely code a loop that reads in lines of a file, then
calls mysub() on each letter in each line?
Or each xml tag on the line?
And I guess the answer is the same as in Perl 5. I don't understand what the problem is with Perl 5's approach:
for <> { mysub($_) for .split: /<null>/; }
Or:
use Rule::XML; for <> { mysub($_) for m:g/(ÂRule::XML::tagÂ)/; }
I'd like to see a similar, simple notation for expressing composite operations. Perhaps this is a macro thing, but macros are still a little fuzzy to me (and I have these horrid memories from Lisp... :(
In general, though, this ties back to my long-ago wish for "separable verb" syntax support: I'd like to see a relatively concise, expressive notation for doing something like a double-loop or arbitrary traversal. The outer product was a delightful example of this kind of thinking -- it's obviously code, but it's totally data-driven.
Iterators may provide some of this, of course. But they provide it in scenarios where the data structure has been "comprehended" beforehand. Dynamic comprehension, if such a phrase can exist, is the obvious next step in DWIMmery.
Given a Tree, or a Trie, or a AvlTree, or a RBTree, it's easy to figure out what $CLASS->getIterator() is going to do. But what's the right way to traverse a C source file? In preprocessor mode it's one thing, in lexer mode it's another.
Is it possible to talk about an iteration template? Say I've got a list of numbers, but I want to iterate only the primes. Something like:
class PrimeNumberIterator is Iterator { method _is_prime() {...} method .next() { my $cand; $cand = SUPER::next() while !_is_prime($cand); return $cand; } }
How do I impose that iteration scheme?
for @list -> $x is PrimeNumberIterator { say $x ; }
Does that work?
Anyway, the point is that we as humans can say things like "look at all the prime numbers in the list ...", so I would like to see a similar level of expressivity in P6. I think P6l was heading that way some time ago, but we got sidetracked by an Apocalypse. :)
Maybe Larry's concept of 'type' has a place here? (Remember that 'type' was described as a restriction of 'class', such that 'odd number' is a type that restricts 'number'.)
Would
for @list -> $x is Prime { say $x ; }
work? What about
for [EMAIL PROTECTED] ~~ Prime ] -> $x { say $x; }
(That last one is really hard to read -- it would wind up demanding a layer of sugar...)
But if type is the only way to do filtering, then we'll wind up with a metatype mechanism for defining types on the fly, so ...
=Austin
-- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 265.6.12 - Release Date: 1/14/2005