Page 1 of 1

Format bug?

Posted: Thu Jul 17, 2008 5:18 pm
by Jeff

Code: Select all

(define (test obj)
  (cond
   ((string? obj) (format "'%s'" obj))
   ((list? obj) (format "[ %s ]" (join (map test obj) ", ")))))

;; expected:
;;   (test '(("foo" "bar") ("baz" "bat")))
;;   "[ [ 'foo', 'bar' ], [ 'baz', 'bat' ] ]"
;; received:
(test '(("foo" "bar") ("baz" "bat")))
"[ [ 'foo', 'bar', [ 'baz', 'bat' ]"

Posted: Thu Jul 17, 2008 7:02 pm
by Lutz
'format' has an old reentrance problem, which needs to be fixed.

Meanwhile use this workaround:

Code: Select all

(define (test obj) 
  (cond 
   ((string? obj) (format "'%s'" obj)) 
   ((list? obj) 
    (let (s (join (map test obj) ", "))
         (format "[ %s ]" s)))))

> (test '(("foo" "bar") ("baz" "bat")))
"[ [ 'foo', 'bar' ], [ 'baz', 'bat' ] ]"

Posted: Thu Jul 17, 2008 8:46 pm
by Jeff
Thanks. I'm already working around using 'string' :)