On Tue, Sep 23, 2008 at 12:05:18PM +0200, Moritz Lenz wrote:
> jason switzer (via RT) wrote:
> > Not all radix constructs are supported yet (in the works). Currently does
> > not support nested notation, such as :10<12*23**3> or functional forms such
> > as :10('1234').
> 
> If such things are to be supported in string-to-number conversions (is
> that specced? where?), ...

S02:2156:

    The generic string-to-number converter will recognize all of these
    forms (including the * form, since constant folding is not available
    to the run time).  Also allowed in strings are leading plus or minus,
    and maybe a trailing Units type for an implied scaling.  Leading and
    trailing whitespace is ignored. 

> ...  it should really take the way through the
> grammar. In the end the user could change what he considers a number by
> modifying the grammar. 

The spec doesn't mention anything about string-to-number conversion
following changes to the the grammar, so Rakudo has taken the opposite
approach -- i.e., the compiler uses the generic string-to-number converter
to evaluate the forms recognized by the grammar.  If this is backwards
then the spec likely needs an update.

> Also note that these expressions could grow arbitrarily complex.

I think the recogized expression are (currently) limited to the 
specific forms outlined in S02.

> > Index: perl6str.pmc
> > ===================================================================
> > --- perl6str.pmc    (revision 31353)
> > +++ perl6str.pmc    (working copy)
> > @@ -23,6 +23,58 @@
> >  #include <ctype.h>
> >  #include <math.h>
> >  
> > +FLOATVAL parse_number(const char** start, const char* stop, FLOATVAL 
> > radix) {
> > +    FLOATVAL number = 0.0;
> > +    //continue until the end or until we've hit a non-digit
> > +    while (*start < stop && isxdigit((unsigned char)**start)) {
> 
> Your usage of isxdigit() makes me wonder - will that work for bases > 16?

Correct, that should probably be isalnum() instead.

Pm

Reply via email to