Format bug?

Started by Jeff, July 17, 2008, 10:18:12 AM

Previous topic - Next topic

Jeff

(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' ]"
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

Lutz

#1
'format' has an old reentrance problem, which needs to be fixed.



Meanwhile use this workaround:


(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' ] ]"

Jeff

#2
Thanks.  I'm already working around using 'string' :)
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code