> 1) "Formats" as classes. What I _want_ to do is to be able to
> associate a named "format" with a given class/instance/output, because
> I tend to use the same few formats over and over. So if I want to
> frequently output numbers as '%-4.2d', I just call it "MoneyFormat" or
> something:
>
> class MoneyFormat is NumFormat {
> sub width { 4 };
> sub precision { 2 };
> sub align { 'right' };
> }
>
> And then later I can say things like:
>
> print $v.as(MoneyFormat); # just pass the class name
> print $v.as(MoneyFormat.new); # or a specific instance
This is fairly trivial to do, and could be done in Perl5 now (except for the
as).
The MoneyFormat class could overload its "to_string" operator(~) to return
the
proper sprintf string for as.
> 2) An analogue to a "rule", but for output instead of input. As we can
> say:
>
> $s ~~ /<number>/
>
> if we've defined a rule called <number>, it feels like it would be
> useful to allow similar "output rules" that format things for
> interpolation. Like:
>
> print "blah blah: <$i:MoneyFormat>";
This just feels weird, and I don't see the benefit of it over
print "blah blah $i.as(MoneyFormat)"
> It would be very useful in the second half of a s///, too (grab a
> match, rewrite it in a canonical form):
>
> $s ~~ s/<number>/<number:MoneyFormat>/;
once again, I think it could just be
$s ~~ s/<number>/$1.as(MoneyFormat)/
Tanton