Format bug?

For the Compleat Fan
Locked
Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Format bug?

Post 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' ]"
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

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

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

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

Thanks. I'm already working around using 'string' :)
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

Locked