Dave Storrs writes: > On Fri, Nov 15, 2002 at 11:50:52PM +0200, [EMAIL PROTECTED] wrote: > > Michael Lazzaro writes: > > depending on WYW . or the casting may be let to happen in two stages > > : string -> num -> specific num type ,e.g. uint16 > > How about if we got adverbial on the problem: > > my $str = "0xff"; > my $i = num $str; > my $i = num $str : uint16; > my $i = num "1.0_731e3" : float; > my $i = num "1.0_898_798_798_794e7" : double; > > And this makes an interesting corner case: > > my $i = num "10_000" : byte; # value too large for 1 byte >
what I dont understand, is how *syntactically* float and company is passed to "num" method/subroutine . if num is *just* another method/subroutine then I would spell your examples like that > my $str = "0xff"; > my $i = num $str; > my $i = num $str : "uint16" ; #or "format"=>"uint16" Ah, but now I see , uint16 *is not a bare word* -- it is class obgect .. so -- now I see how you examples would work . num can accept a class object as argument. But then it have to be predeclard . I heard in the previous discussions that it may happen that to use uint16 and friends one will have to say "use ..." so we can have : class str{ method num(Class $c) { ... } method num(str $format) { ... } ..... } > I can see two ways to handle this--we can have a compile-time warning, > or we could store it to the smallest type that will hold the value and > issue a warning. > > > > > (4) -- We want to be able to output numbers to strings according to > > > specific formatting rules. One way to do this (aside from using > > > sprintf) is to use sprintf-style formatting strings, perhaps as > > > properties to tie them to individual instances: > > > > > > my int $i = literal "0xff" but as_string('%02x'); > > Actually, this would be a good reason to have a function called > "literal" -- if it went both ways. So, I could do this: > > print literal(200+55):hex; # == print "0xff"; > print literal("0xff)); # == print 255; why not str ? > print str( 200+55 :"format"=>"hex"); # == print "0xff"; > print str("0xff"); # == print 255; only that here one haveto use "hex" because hex is not a type or class. > > --Dks > > arcadi