[plt-scheme] syntax question
(define-syntax (define-readable-structure stx)
(syntax-case stx ()
[(define-readable-structure name ((field reader) ...))
(let ([prefix-name
(lambda (pre)
(datum->syntax-object
stx
(string->symbol
(string-append
pre "-"
(symbol->string (syntax-e (syntax name)))))))])
(with-syntax ([read-name (prefix-name "read")]
[make-name (prefix-name "make")])
#`(begin
(define-struct name (field ...) (make-inspector))
(define (read-name port)
(make-name (reader port) ...)))))]))
;; test
(define-readable-structure name1 ((field1 read) (field2 read)))
;; the names exist
make-name1
name1-field1
name1-field2
read-name1
;; the reading works
(let* ([s "1 2"]
[i (open-input-string s)])
(equal? (read-name1 i) (make-name1 1 2)))
-- Matthias