Re: [Scheme-reports] library at file level
Aaron W. Hsu 15 May 2013 20:34 UTC
On Wed, 2013-05-15 at 22:11 +0200, Taylan Ulrich B. wrote:
> On the other hand, I found the equivalent practice, using `let-syntax',
> very useful in a recent piece of code of mine[0]; it drastically reduced
> the repetitiveness of a series of definitions. The only alternative I
> can think of which achieves this is to define the macro I used in the
> global scope, which would not be very nice.
I will actually (if I can find the time) be proposing what I consider a
much cleaner alternative. Here's the example you give from your file:
(let-syntax
((define-numeric-types
(syntax-rules ()
((_ (name size ref-fn set-fn) ...)
(begin
(define name
(make-bytestructure-descriptor
(list bsd:simple size ref-fn set-fn)))
...)))))
(define-numeric-types
(float
4 bytevector-ieee-single-native-ref
bytevector-ieee-single-native-set!)
(double
8 bytevector-ieee-double-native-ref
bytevector-ieee-double-native-set!)
(int8 1 bytevector-s8-ref bytevector-s8-set!)
(uint8 1 bytevector-u8-ref bytevector-u8-set!)
(int16 2 bytevector-s16-native-ref bytevector-s16-native-set!)
(uint16 2 bytevector-u16-native-ref bytevector-u16-native-set!)
(int32 4 bytevector-s32-native-ref bytevector-s32-native-set!)
(uint32 4 bytevector-u32-native-ref bytevector-u32-native-set!)
(int64 8 bytevector-s64-native-ref bytevector-s64-native-set!)
(uint64 8 bytevector-u64-native-ref bytevector-u64-native-set!)))
And in the new proposal, you could convert this to the following:
(module ()
(define-syntax define-numeric-type
(syntax-rules ()
[(_ (name size ref-fn set-fn) ...)
(begin
(begin
(export name)
(define name
(make-bytestructure-descriptor
(list bsd:simple size ref-fn set-fn))))
...)]))
(define-numeric-types
(float 4 bytevector-ieee-single-native-ref
bytevector-ieee-single-native-set!)
(double 8 bytevector-ieee-double-native-ref
bytevector-ieee-double-native-set!)
(int8 1 bytevector-s8-ref bytevector-s8-set!)
(uint8 1 bytevector-u8-ref bytevector-u8-set!)
(int16 2 bytevector-s16-native-ref bytevector-s16-native-set!)
(uint16 2 bytevector-u16-native-ref bytevector-u16-native-set!)
(int32 4 bytevector-s32-native-ref bytevector-s32-native-set!)
(uint32 4 bytevector-u32-native-ref bytevector-u32-native-set!)
(int64 8 bytevector-s64-native-ref bytevector-s64-native-set!)
(uint64 8 bytevector-u64-native-ref bytevector-u64-native-set!)))
--
Aaron W. Hsu | arcfide@sacrideo.us | http://www.sacrideo.us
_______________________________________________
Scheme-reports mailing list
Scheme-reports@scheme-reports.org
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports