format bugs, etc.

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?
Locked
kosh
Posts: 72
Joined: Sun Sep 13, 2009 5:38 am
Location: Japan
Contact:

format bugs, etc.

Post 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

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: format bugs, etc.

Post 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... :)

kosh
Posts: 72
Joined: Sun Sep 13, 2009 5:38 am
Location: Japan
Contact:

Re: format bugs, etc.

Post by kosh »

(rand 0)'s different behaviour is well-documented...
mmm... I should check the documents.
sorry for misread the situation.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: format bugs, etc.

Post 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.

Locked