Page 1 of 1

format bugs, etc.

Posted: Sat Dec 12, 2009 9:40 pm
by kosh
## 1. `format' function returns a value different from `printf()'

Code: Select all

(format "%#05x" 10)
;-> ERR: problem in format string in function format : "%#05x"

(import "libc.so.6" "printf")
(printf "%#05x" 10)
;-> 0x00a
;=> 5

(format "%c" 0)
; => "" (empty string)

(printf "%c" 0)
;-> ^@ ("\000")
;=> 1
## 2. `(rand 0)' returns not integer value.

Code: Select all

(rand 0)
;=> true
---
kosh

Re: format bugs, etc.

Posted: Sat Dec 12, 2009 9:52 pm
by cormullion
(rand 0)'s different behaviour is well-documented...

http://en.wikibooks.org/wiki/Introducti ... om_numbers
http://www.newlisp.org/downloads/newlis ... .html#rand

and it's probably best that it doesn't return a number otherwise you might never notice that you asked for a random integer between 0 and -1... :)

Re: format bugs, etc.

Posted: Sat Dec 12, 2009 11:12 pm
by kosh
(rand 0)'s different behaviour is well-documented...
mmm... I should check the documents.
sorry for misread the situation.

Re: format bugs, etc.

Posted: Sun Dec 13, 2009 2:09 pm
by Lutz
newLISP 'format' and C printf() are simply differemt things and on purpose. The C function returns the number of characters written, the 'format' function returns the the formatted string.

The format characters for 'format' are only a subset of what can be used in C and there are slight differences how integer precision is handled.

See the documentation for 'format' for details.