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

sprintf and snake envy

Thread Next
From:
Brad Bowman
Date:
July 4, 2006 00:06
Subject:
sprintf and snake envy
Message ID:
44AA138E.70304@bereft.net
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)

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..)

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.

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

So, any takers?

Brad

[1] http://dev.perl.org/perl6/doc/design/exe/E07.html
[2] http://www.python.org/doc/QuickRef.html#BasicTypes
    Search for: "Format operator"
-- 
 Bravery and cowardice are not things which can be conjectured in times
 of peace.  They are in different categories. -- Hagakure

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About