[gambit-list] print vs. display segfault
Christian Jaeger
christian at pflanze.mine.nu
Thu Apr 26 10:48:52 EDT 2007
On my 4.0 beta 21 installation (compiled with single-host and shared),
this doesn't segfault:
(define (string-escape string chars
#!optional (escape (lambda (c) (print #\\ c))) port)
(let ((pred? (%string-charset->pred chars))
(output (or port (open-output-string ""))))
(with-output-to-port
output
(&
(string-for-each ;; <--from srfi-13
(lambda (c)
(if (pred? c)
(escape c)
(print c))) ; this is where the anti-magic happens
string)))
(or port (get-output-string output))))
Note that I did change it at two locations:
- with-output-port is not present in beta 21 (neither did I find it in
the manual of beta 22), so I did change to with-output-to-port
- with-output-to-port expect a thunk as second argument, so I did wrap
it in (& ) where this is a macro defined by myself (I deserve the right
to use my own code too, now :^)):
(define-macro (& first . rest)
`(lambda() ,first , at rest))
Christian.
More information about the Gambit-list
mailing list