sprintf and snake envy
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
Re: sprintf and snake envy
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 $^c.as('%03d') quote types.}(:c(Inf),:langPerl) 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. :) Larry
Re: sprintf and snake envy
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} 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. I'm not convinced that sprintf needs an operator. It's not commonly used in any code I've looked at, which to me suggests that it's not good huffman coding to use up a terse symbol for it, denying that symbol to something else. Nicholas Clark
Re: sprintf and snake envy
On Tue, Jul 04, 2006 at 05:27:33PM +0100, Nicholas Clark wrote: : I'm not convinced that sprintf needs an operator. It's not commonly used in : any code I've looked at, which to me suggests that it's not good huffman : coding to use up a terse symbol for it, denying that symbol to something : else. Well, we kinda do have an operator already, if you consider infix:as to be a variant of .as(). $c as '%03d' $c.as('%03d') but it's arguable which is better in a string: $a = {$c as '%03d'} $a = $c.as('%03d') But that's backwards from Python's % operator. Actually, I think I like the Perl way better for single patterns... :) Larry
[svn:perl6-synopsis] r9812 - doc/trunk/design/syn
Author: audreyt Date: Tue Jul 4 15:37:53 2006 New Revision: 9812 Modified: doc/trunk/design/syn/S11.pod Log: * S11: To maintain implementation neutrality, the p6-in-p5 incantation is no longer: use v6-pugs; it's now: use v6-**; Modified: doc/trunk/design/syn/S11.pod == --- doc/trunk/design/syn/S11.pod(original) +++ doc/trunk/design/syn/S11.podTue Jul 4 15:37:53 2006 @@ -12,9 +12,9 @@ Maintainer: Larry Wall [EMAIL PROTECTED] Date: 27 Oct 2004 - Last Modified: 22 Apr 2006 + Last Modified: 4 Jul 2006 Number: 11 - Version: 12 + Version: 13 =head1 Overview @@ -272,10 +272,10 @@ means the same thing. As a variant of that, the current Perl 5 incantation to switch to Perl 6 parsing is -use v6-pugs; +use v6-**; (though in Perl 5 this actually ends up calling the v6.pm module with a -'-pugs' argument for insane-but-useful reasons.) +C-** argument for insane-but-useful reasons.) For wildcards any valid smartmatch selector works:
The exact value of infinity [Was: Re: sprintf and snake envy]
On Jul 05, 2006, at 01:25 , Larry Wall wrote: What made me laugh is that Pugs knows the exact value of infinity: pugs my $a = {$^lang has $^c.as('%03d') quote types.}(:c (Inf),:langPerl) Perl has 1797693134862315907729305190789024733617976978942306572734300811577326 7580550096313270847732240753602112011387987139335765878976881441662249 2847430639474124377767893424865485276302219601246094119453082952085005 7688381506823424628814739131105408272371633505106845862982399472459384 79716304835356329624224137216 quote types. Larry, you almost wrecked my MacBook Pro with the coffee I was sipping :) I think I found the reason why Pugs knows the exact value of infinity. That's GHC that tells pugs the exact value thereof. This is Infinity according to Pugs. ./src/Pugs/AST/Internals.hs doCast (VStr Inf) = return $ 1/0 And this is what GHC thinks what Infinity is. Prelude 2^1023 == 1/0 False Prelude 2^1024 == 1/0 True Dan the Pugs Walker