From: Timothy J. H. <ti...@cs...> - 2004-06-07 14:44:57
|
On Jun 7, 2004, at 10:24 AM, Ken Anderson wrote: > So the remaining issue is what should (string->number "08") return. > It currently returns #f. i was hoping it would return 8. I can modify it so that string->number does not support the Java octal syntax by default. This little issue actually goes to the heart of JScheme since what is unique about Jscheme is the tight integration with Java and that integration is made possibly by our decision to adopt the Java primitive types as the Scheme base types. The Java literal syntax is then essential to making JScheme integrate smoothly with Java. Perhaps the idea should be that string->number has Scheme R4RS as its heritage and should therefore rely on the R4RS syntax primarily (hence disallowing octal notation entirely???) We could then follow Jonathan's suggestion and have a string->JavaNumber procedure which would parse strings in the same way as the default Scheme reader parses numbers. This thread also raises the issue of documentation. One of my goals is to minimize documentation by outsourcing it, i.e. we can say that the JScheme literal syntax (at least in useJavaSyntax mode) is precisely the Java Literal syntax mode, except for some slight differences (#t #f #'...' #(.....)) This frees the Java programmer from having to learn a new syntax for literals and eases the transition between the two languages. ---Tim---- > > At 07:27 PM 6/6/2004 -0400, Timothy John Hickey wrote: >> I've modified string->number so that in the base 10 case it allows >> leading zeroes... >> The following Unit tests all pass in the current version of JScheme... >> >> "06/06/2004" ;; literal syntax, TJH >> >> ;; Default literal syntax is for Java literals, >> >> ;; but string->number will treat leading zeroes as decimal if base >> 10 is specified >> >> (equal? (.getClass '081) jsint.Symbol.class) >> >> (equal? (.getClass '0123Dig) jsint.Symbol.class) >> >> (equal? (.getClass '0123) java.lang.Integer.class) >> >> (equal? (string->number "081" 10) 81) >> >> (equal? (string->number "010") 10) >> >> (equal? (string->number "010" 8) 8) >> >> (equal? (tryCatch (string->number "081" 8) (lambda(e) 'error)) >> 'error) >> >> (equal? (string->number "08") #f) >> >> (equal? (string->number "08" 10) 8) >> >> (equal? (string->number "10") 8) >> >> (equal? (string->number "10" 10) 10) >> >> The implementation of string->number in the base 10 case is >> >>> public static Object schemeStringToNumber(String tok, int rdx) { >>> try { return U.toNum(Long.parseLong(tok, rdx)); } >>> catch (NumberFormatException e) { >>> try { >>> if (rdx!=10) >>> return U.FALSE; >>> else return new Double(tok); } >>> catch (NumberFormatException e2) >>> { return U.FALSE; } >>> } >>> } >> >> ---Tim--- >> >> >> >> ------------------------------------------------------- >> This SF.Net email is sponsored by the new InstallShield X. >> From Windows to Linux, servers to mobile, InstallShield X is the one >> installation-authoring solution that does it all. Learn more and >> evaluate today! http://www.installshield.com/Dev2Dev/0504 >> _______________________________________________ >> Jscheme-devel mailing list >> Jsc...@li... >> https://lists.sourceforge.net/lists/listinfo/jscheme-devel > > > > ------------------------------------------------------- > This SF.Net email is sponsored by the new InstallShield X. >> From Windows to Linux, servers to mobile, InstallShield X is the one > installation-authoring solution that does it all. Learn more and > evaluate today! http://www.installshield.com/Dev2Dev/0504 > _______________________________________________ > Jscheme-devel mailing list > Jsc...@li... > https://lists.sourceforge.net/lists/listinfo/jscheme-devel |