[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme-reports] library at file level



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@x | http://www.sacrideo.us

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports