newLISP Fan Club

Forum => Anything else we might add? => Topic started by: Jeff on July 17, 2008, 10:18:12 AM

Title: Format bug?
Post by: Jeff on July 17, 2008, 10:18:12 AM
(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' ]"
Title:
Post by: Lutz on July 17, 2008, 12:02:12 PM
'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' ] ]"
Title:
Post by: Jeff on July 17, 2008, 01:46:34 PM
Thanks.  I'm already working around using 'string' :)