newLISP Fan Club

Forum => newLISP and the O.S. => Topic started by: zool on November 01, 2005, 04:21:47 PM

Title: Bug in (int)
Post by: zool on November 01, 2005, 04:21:47 PM
Consider the following:



(int "07") => 7



(int "08") => 0



Is this intentional?



/Christer
Title:
Post by: Sammo on November 01, 2005, 04:30:24 PM
Hello Christer,



It is intentional! Unless told otherwise (see manual), 'int' understands that number strings beginnning with numeral "0" (zero) are octal numbers. Since "08" is not a valid octal number, 'int' stops parsing the octal string at "0" and returns zero as the result.



The manual gives complete details and explains the optional parameters to 'int' to extract the result you might be expecting.



-- Sam
Title:
Post by: Lutz on November 01, 2005, 06:34:23 PM
yes, and 0 (zero) as an indicator for octal numbers is a common thing in programming languages, 'C", Perl and Python do similar, try:



~> echo "print 077" | perl
63

~> echo "print 077" | python
63


the above executed in a unix/bash shell on Mac OSX



Lutz
Title:
Post by: Dmi on November 02, 2005, 01:22:07 PM
I've lost one evening a month ago trying to debug similar problem ;-)

something like this will help:
(define (int10 i) (int i 0 10))