develooper Front page | perl.perl6.language | Postings from July 2006

Re: sprintf and snake envy

Thread Previous | Thread Next
Larry Wall
July 4, 2006 09:26
Re: sprintf and snake envy
Message ID:
On Tue, Jul 04, 2006 at 05:06:54PM +1000, Brad Bowman wrote:
: Hello,
: It seems that sprintf is will still be around in Perl 6 [1],
: and that sprintf formats will be available using the .as() method.
: While looking at some Python docs [2] I noticed two things that might
: be worth stealing; a sprintf operator (%) and named parameters in 
: the format string:
: a = '%(lang)s has %(c)03d quote types.' % {'c':2, 'lang':'Python}
: (This example made me laugh)

What made me laugh is that Pugs knows the exact value of infinity:

    pugs> my $a = {"$^lang has $^'%03d') quote types."}(:c(Inf),:lang<Perl>)
    "Perl has 179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137216 quote types."

: Since perl6 has named parameters, pairs and slurpy hashes, I think
: sprintf should be taught to use them.  Syntax is an exercise for the
: reader.  (Unifying the '%2$d' with the named syntax would be nice..)

Yes, I18n and L10n requires some kind of templating engine.  Whether sprintf
is that engine is another question.

: The operator need is less clear cut.  Overloading '%' certainly wouldn't
: make sense in Perl 6 and the presence of .as() may cover the common cases.

It's also possible that some ~~ variant also binds a capture to
an interpolation.  That would have the advantage of working in
either order.

: Some alternatives are idiomatic combinations of interpolation and .as(),
: Perl6::Form forms, and custom quote operators/adverbs.
: So, any takers?

We don't need any takers, we need any givers.  :)


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