David Rush
2009-09-25 12:16:28 UTC
Hi y'all -
I have been deeply buried in wrapping various C APIs, and the
repetitive bytevector trickery has led me to a bit of macrology. Now,
this is my first time *ever* using LET-SYNTAX, so maybe I am getting
something wrong here, but using PLT 4.2.1 the following macro expands
as I (almost) expect
; -*- scheme -*-
(define-syntax define-wrapped-field
(syntax-rules ()
((define-wrapped-field (base field) spec0 spec+ ...)
(let-syntax
((wrap-spec
(syntax-rules ()
((wrap-spec (reader converter raw))
(define reader
(bvw-access-wrapper
(lambda (raw*) raw)
(lambda (init) (converter base 'field init)))
))
((wrap-spec (writer converter!))
(define writer
(bvw-update-wrapper
(lambda (bv val) (converter! base 'field bv val)))
))
)))
(begin
(wrap-spec spec0)
(wrap-spec spec+)
...
'de-nada
)))
))
; the above is used thusly
(define-wrapped-field (MQOD DynamicQName)
(mqod-dynamic-queue-name bvw-z-string "unknown")
(mqod-dynamic-queue-name bvw-z-string!)
)
; -*- end scheme -*-
The expansion under PLT becomes
(begin
(define mqod-object-name
(bvw-access-wrapper
(lambda (raw*) "unknown")
(lambda (init) (bvw-z-string MQOD 'ObjectName init))))
(define mqod-object-name!
(bvw-update-wrapper
(lambda (bv val) (bvw-z-string! MQOD 'ObjectName bv val))))
'de-nada))
which is totally expected. Larceny does comething else which looks
more or less like
((lambda ()
((lambda (\x2e;mqod-object-name\x7c;4 \x2e;mqod-object-name!\x7c;4)
(begin
(set! \x2e;mqod-object-name\x7c;4 ...)
...
'de-nada
))
(\x2e;unspecified)
(\x2e;unspecified))))
which would be fine *I suppose* except that it does *not* end up
defining the new bindings at toplevel (in R5RS mode, I have not tried
the other modes). Is this an actual bug?
Additionally, the inclusion of the expression 'de-nada appears to be a
new requirement (both in Larceny and PLT). I recall that using BEGIN
to encapsulate multiple toplevel defines was pretty much the standard
way to handle this kind of thing in R[45]RS. Is this really the way it
is supposed to work? That is quite a pernicious minor change, if it
is.
david rush
I have been deeply buried in wrapping various C APIs, and the
repetitive bytevector trickery has led me to a bit of macrology. Now,
this is my first time *ever* using LET-SYNTAX, so maybe I am getting
something wrong here, but using PLT 4.2.1 the following macro expands
as I (almost) expect
; -*- scheme -*-
(define-syntax define-wrapped-field
(syntax-rules ()
((define-wrapped-field (base field) spec0 spec+ ...)
(let-syntax
((wrap-spec
(syntax-rules ()
((wrap-spec (reader converter raw))
(define reader
(bvw-access-wrapper
(lambda (raw*) raw)
(lambda (init) (converter base 'field init)))
))
((wrap-spec (writer converter!))
(define writer
(bvw-update-wrapper
(lambda (bv val) (converter! base 'field bv val)))
))
)))
(begin
(wrap-spec spec0)
(wrap-spec spec+)
...
'de-nada
)))
))
; the above is used thusly
(define-wrapped-field (MQOD DynamicQName)
(mqod-dynamic-queue-name bvw-z-string "unknown")
(mqod-dynamic-queue-name bvw-z-string!)
)
; -*- end scheme -*-
The expansion under PLT becomes
(begin
(define mqod-object-name
(bvw-access-wrapper
(lambda (raw*) "unknown")
(lambda (init) (bvw-z-string MQOD 'ObjectName init))))
(define mqod-object-name!
(bvw-update-wrapper
(lambda (bv val) (bvw-z-string! MQOD 'ObjectName bv val))))
'de-nada))
which is totally expected. Larceny does comething else which looks
more or less like
((lambda ()
((lambda (\x2e;mqod-object-name\x7c;4 \x2e;mqod-object-name!\x7c;4)
(begin
(set! \x2e;mqod-object-name\x7c;4 ...)
...
'de-nada
))
(\x2e;unspecified)
(\x2e;unspecified))))
which would be fine *I suppose* except that it does *not* end up
defining the new bindings at toplevel (in R5RS mode, I have not tried
the other modes). Is this an actual bug?
Additionally, the inclusion of the expression 'de-nada appears to be a
new requirement (both in Larceny and PLT). I recall that using BEGIN
to encapsulate multiple toplevel defines was pretty much the standard
way to handle this kind of thing in R[45]RS. Is this really the way it
is supposed to work? That is quite a pernicious minor change, if it
is.
david rush
--
GPG Public key at http://cyber-rush.org/drr/gpg-public-key.txt
GPG Public key at http://cyber-rush.org/drr/gpg-public-key.txt