Re: Help! Strings -> Numbers

2002-11-22 Thread Dave Storrs
On Fri, Nov 22, 2002 at 12:10:11PM -0800, Michael Lazzaro wrote: > On Friday, November 22, 2002, at 10:59 AM, Luke Palmer wrote: > >> From: Michael Lazzaro <[EMAIL PROTECTED]> > I've been under the impression that the following would _not_ work: > > $s ~~ //; > print "I found $number";

Re: Help! Strings -> Numbers

2002-11-22 Thread Michael Lazzaro
On Friday, November 22, 2002, at 10:59 AM, Luke Palmer wrote: From: Michael Lazzaro <[EMAIL PROTECTED]> (This is a bit off-topic, but it's a tiny bit sad that you can name subrules, but you can't refer to them by name in the interpolation unless you use hypothetical vars. Eh, no biggie: it would

Re: Help! Strings -> Numbers

2002-11-22 Thread Luke Palmer
> Date: Fri, 22 Nov 2002 10:49:08 -0800 > From: Michael Lazzaro <[EMAIL PROTECTED]> > > Or, using hypothetical vars: > > $s ~~ s/ $num := /$num.as(MoneyFormat)/; > > (This is a bit off-topic, but it's a tiny bit sad that you can name > subrules, but you can't refer to them by name in the i

Re: Help! Strings -> Numbers

2002-11-22 Thread Michael Lazzaro
On Thursday, November 21, 2002, at 11:22 AM, Tanton Gibbs wrote: It would be very useful in the second half of a s///, too (grab a match, rewrite it in a canonical form): $s ~~ s///; once again, I think it could just be $s ~~ s//$1.as(MoneyFormat)/ Or, using hypothetical vars:

Re: Help! Strings -> Numbers

2002-11-21 Thread Jonathan Scott Duff
On Wed, Nov 20, 2002 at 05:51:17PM -0500, Tanton Gibbs wrote: > It's going to be hard to beat sprintf( "%x", $i ) for clarity or > conciseness. my $s = "%x" % $i; # python wins for conciseness :-) -Scott -- Jonathan Scott Duff [EMAIL PROTECTED]

Re: Help! Strings -> Numbers

2002-11-21 Thread Piers Cawley
Larry Wall <[EMAIL PROTECTED]> writes: > On Thu, Nov 21, 2002 at 01:29:32AM -0500, Tanton Gibbs wrote: > : Properties have bothered me, but for a different reason. It appears that > : everyone's answer to everything is "make it a property!" > > Yes, properties should generally be a last resort, n

Re: Help! Strings -> Numbers

2002-11-21 Thread Dave Storrs
On Thu, Nov 21, 2002 at 09:10:53AM -0800, Larry Wall wrote: > On Wed, Nov 20, 2002 at 10:16:54PM -0800, Dave Storrs wrote: > : As a tangent...one of the things that has bothered me about "but" and > : "is" for properties since the beginning is that they make for > : excessively long code. Does th

Re: Help! Strings -> Numbers

2002-11-21 Thread Dave Whipp
"Michael Lazzaro" <[EMAIL PROTECTED]> wrote : > > 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 j

Re: Help! Strings -> Numbers

2002-11-21 Thread Tanton Gibbs
> 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: > >

Re: Help! Strings -> Numbers

2002-11-21 Thread Michael Lazzaro
On Thursday, November 21, 2002, at 12:16 AM, Dave Storrs wrote: I do agree that having it be a method (and hence overloadable) is the best solution. I just wish there were some way to get away from those dratted sprintf format strings. Amen. God, I've hated those things for years. And yet m

Re: Help! Strings -> Numbers

2002-11-21 Thread Tanton Gibbs
> If I'm understanding them correctly, another way to think of runtime > properties is "dynamic inheritance", or more specifically > "instance-based inheritance". When you say: > > $v but foo(5); > > You're saying that instance/value $v now inherits the behaviors of > foo(5), in addition to it

Re: Help! Strings -> Numbers

2002-11-21 Thread Michael Lazzaro
On Thursday, November 21, 2002, at 12:24 AM, Dave Storrs wrote: On Thu, Nov 21, 2002 at 01:29:32AM -0500, Tanton Gibbs wrote: Properties have bothered me, but for a different reason. It appears that everyone's answer to everything is "make it a property!" Properties are just strange to compre

Re: Help! Strings -> Numbers

2002-11-21 Thread Larry Wall
On Thu, Nov 21, 2002 at 01:29:32AM -0500, Tanton Gibbs wrote: : Properties have bothered me, but for a different reason. It appears that : everyone's answer to everything is "make it a property!" Yes, properties should generally be a last resort, not a first resort. : Properties are just strange

Re: Help! Strings -> Numbers

2002-11-21 Thread Larry Wall
On Wed, Nov 20, 2002 at 10:16:54PM -0800, Dave Storrs wrote: : # Could you really tell what this does at a glance? : my $s = ~hex:w4p2d0rs $i; : : my $s = ~hex $i but width 4 : but precision 2 : but padded 0 :

Re: Help! Strings -> Numbers

2002-11-21 Thread Dave Storrs
On Thu, Nov 21, 2002 at 03:26:09AM -0500, Tanton Gibbs wrote: > Dave Storrs wrote > > best solution. I just wish there were some way to get away from those > > dratted sprintf format strings. > > Well, for the general case, you could create convienence functions that > handle getting the correct

Re: Help! Strings -> Numbers

2002-11-21 Thread Tanton Gibbs
> > > my str $s = sprintf("%x", $i);# 30 characters > > > my str $s = hex $i; # 19 characters > > > my $s = ~hex $i; # 16 characters > > > > I think these are good, but I really think that Larry's idea of an "as" > > function is the best. Not only does it provide

Re: Help! Strings -> Numbers

2002-11-21 Thread Dave Storrs
On Thu, Nov 21, 2002 at 01:29:32AM -0500, Tanton Gibbs wrote: > > > As a tangent...one of the things that has bothered me about "but" and > > "is" for properties since the beginning is that they make for > > excessively long code. Does this bother anyone else? > > > > --Dks > > Properties have b

Re: Help! Strings -> Numbers

2002-11-21 Thread Dave Storrs
On Thu, Nov 21, 2002 at 01:22:50AM -0500, Tanton Gibbs wrote: > > I actually rather like MikeL's suggestion for the unary ops; clear, > > concise, and highly readable. And look: > > > > my str $s = sprintf("%x", $i);# 30 characters > > my str $s = hex $i; # 19 characters > > my $

Re: Help! Strings -> Numbers

2002-11-20 Thread Tanton Gibbs
> As a tangent...one of the things that has bothered me about "but" and > "is" for properties since the beginning is that they make for > excessively long code. Does this bother anyone else? > > --Dks Properties have bothered me, but for a different reason. It appears that everyone's answer to

Re: Help! Strings -> Numbers

2002-11-20 Thread Tanton Gibbs
> I actually rather like MikeL's suggestion for the unary ops; clear, > concise, and highly readable. And look: > > my str $s = sprintf("%x", $i);# 30 characters > my str $s = hex $i; # 19 characters > my $s = ~hex $i; # 16 characters I think these are good, but

Re: Help! Strings -> Numbers

2002-11-20 Thread Dave Storrs
On Wed, Nov 20, 2002 at 05:51:17PM -0500, Tanton Gibbs wrote: > > It's going to be hard to beat sprintf( "%x", $i ) for clarity or > conciseness. Unfortunately, it's pretty easy to beat it for readability. It's also a holdover from C, an ancestor language that we are (at least to a degree) tryi

Re: Help! Strings -> Numbers

2002-11-20 Thread Tanton Gibbs
Larry wrote: > "\$i is $i.format('%04x')" > "\$i is $i.form('%04x')" > "\$i is $i.frm('%04x')" > "\$i is $i.as('%04x')" > "\$i is $i.f('%04x')" If we keep it a method, then we do have the added benefit of being able to override it for custom classes...something that sprintf doe

Re: Help! Strings -> Numbers

2002-11-20 Thread Larry Wall
On Wed, Nov 20, 2002 at 02:46:22PM -0800, Michael Lazzaro wrote: : On Wednesday, November 20, 2002, at 01:45 PM, Tanton Gibbs wrote: : string interpolation? (where we need it most!) I agree. But it's already there. We can interpolate method calls. : "\$i is $(sprintf('%04x',$i))" Assu

Re: Help! Strings -> Numbers

2002-11-20 Thread Tanton Gibbs
> I'd certainly like a way to easily (1) treat a string as bin/oct/hex, > and (2) stringify a number to bin/oct/hex, because those are two pretty > common cases. I've tried tons of things to get a more general syntax, > and nothing is really working. The string interpolation case is the > most in

Re: Help! Strings -> Numbers

2002-11-20 Thread Michael Lazzaro
On Wednesday, November 20, 2002, at 01:45 PM, Tanton Gibbs wrote: my int $i is formatted('%4x'); $i = 255; print $i;# prints '00ff'; I too don't see much use in the former. The latter puts distance between the formatting and the thing being formatted and that can't be good.

Re: Help! Strings -> Numbers

2002-11-20 Thread Tanton Gibbs
> > my int $i is formatted('%4x'); > > $i = 255; > > print $i;# prints '00ff'; > > > > Anyone care to comment? > > I too don't see much use in the former. The latter puts distance between > the formatting and the thing being formatted and that can't be good. In situations such a

Re: Help! Strings -> Numbers

2002-11-20 Thread Jonathan Scott Duff
On Tue, Nov 19, 2002 at 10:59:02AM -0800, Michael Lazzaro wrote: > (A) Unification of Literal <--> Stringified Numeric Behaviors > > An old proposal that I can't find anymore suggested that strings should > be converted to a number according to the exact same rules as literals, > such that: > >

Re: Help! Strings -> Numbers

2002-11-20 Thread Larry Wall
On Wed, Nov 20, 2002 at 10:05:38AM -0800, Michael Lazzaro wrote: : On Tuesday, November 19, 2002, at 06:34 PM, Larry Wall wrote: : >On Tue, Nov 19, 2002 at 10:59:02AM -0800, Michael Lazzaro wrote: : >: (A) Unification of Literal <--> Stringified Numeric Behaviors : >: : >: 0123 == "0123" : >

Re: Help! Strings -> Numbers

2002-11-20 Thread Michael Lazzaro
On Tuesday, November 19, 2002, at 06:34 PM, Larry Wall wrote: On Tue, Nov 19, 2002 at 10:59:02AM -0800, Michael Lazzaro wrote: : (A) Unification of Literal <--> Stringified Numeric Behaviors : : 0123 == "0123" : 0xff == "0xff" : 20#1gj == "20#1gj" : 1e10 == "1e10" : : i

Re: Help! Strings -> Numbers

2002-11-19 Thread Larry Wall
On Tue, Nov 19, 2002 at 10:59:02AM -0800, Michael Lazzaro wrote: : OK, back to this, so we can finish it up: we have a number of proposals : & questions re: string-to-num conversions, and from Luke we have some : initial docs for them that need completing. Can I get more feedback on : these iss

Re: Help! Strings -> Numbers

2002-11-19 Thread Paul Johnson
Michael Lazzaro said: > (A) Unification of Literal <--> Stringified Numeric Behaviors > > An old proposal that I can't find anymore suggested that strings should > be converted to a number according to the exact same rules as literals, > such that: > > 0123 == "0123" > 0xff == "0xff

Re: Help! Strings -> Numbers

2002-11-19 Thread Dave Whipp
"Michael Lazzaro" <[EMAIL PROTECTED]> wrote: > OK, back to this, so we can finish it up: we have a number of proposals > & questions re: string-to-num conversions, and from Luke we have some > initial docs for them that need completing. Can I get more feedback on > these issues, plz, and any other

Re: Help! Strings -> Numbers

2002-11-19 Thread Angel Faus
> > (E) We need to finalize what happens when a string isn't a number, > or has additional trailing stuff. Damian gave his initial > preference, but we need to verify & set in stone: > > my int $i = 'foo'; # 0, NaN, undef, or exception? > my int $i = '5foo'; # 5, NaN, undef, or exce