Subject: bug#11887: string->number edge cases

From: Mark H Weaver <[email-masked]>
Date: Wed, 06 Mar 2013 11:55:30 -0500

Daniel Llorens <[email-masked]> writes:

> I think this isn't working as it should either.
>
> scheme@(guile-user)> +1i
> $1 = 0.0+1.0i
> scheme@(guile-user)> 1i
> ;;; <unknown-location>: warning: possibly unbound variable `#{1i}#'
> ERROR: In procedure #<procedure 101d6d4a0 ()>:
> ERROR: In procedure module-lookup: Unbound variable: #{1i}#

No, this is correct.  Scheme requires a sign before an imaginary part.
See R5RS section 7.1.1 (Lexical structure).

    Thanks,
      Mark

--8<---------------cut here---------------start------------->8---
  <number> -> <num 2>| <num 8>
       | <num 10>| <num 16>
  
  The following rules for <num R>, <complex R>, <real R>, <ureal R>,
  <uinteger R>, and <prefix R> should be replicated for R = 2, 8, 10,
  and 16.  There are no rules for <decimal 2>, <decimal 8>, and <decimal
  16>, which means that numbers containing decimal points or exponents
  must be in decimal radix.
  
  <num R> -> <prefix R> <complex R>
  <complex R> -> <real R> | <real R> @ <real R>
      | <real R> + <ureal R> i | <real R> - <ureal R> i
      | <real R> + i | <real R> - i
      | + <ureal R> i | - <ureal R> i | + i | - i
  <real R> -> <sign> <ureal R>
  <ureal R> -> <uinteger R>
      | <uinteger R> / <uinteger R>
      | <decimal R>
  <decimal 10> -> <uinteger 10> <suffix>
      | . <digit 10>+ #* <suffix>
      | <digit 10>+ . <digit 10>* #* <suffix>
      | <digit 10>+ #+ . #* <suffix>
  <uinteger R> -> <digit R>+ #*
  <prefix R> -> <radix R> <exactness>
      | <exactness> <radix R>
  
  <suffix> -> <empty>
      | <exponent marker> <sign> <digit 10>+
  <exponent marker> -> e | s | f | d | l
  <sign> -> <empty>  | + |  -
  <exactness> -> <empty> | #i | #e
  <radix 2> -> #b
  <radix 8> -> #o
  <radix 10> -> <empty> | #d
  <radix 16> -> #x
  <digit 2> -> 0 | 1
  <digit 8> -> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
  <digit 10> -> <digit>
  <digit 16> -> <digit 10> | a | b | c | d | e | f
--8<---------------cut here---------------end--------------->8---