Here's a library which exports a hashtable. The library also contains expressions which populate the hashtable:
(library (abc-1)
(export tbl)
(import (rnrs))
(define tbl (make-eq-hashtable))
(hashtable-set! tbl 'a 10)
(hashtable-set! tbl 'b 20)
(hashtable-set! tbl 'c 30))
Here's another version of the library which exports a procedure which can be used to populate the hashtable:
(library (abc-2)
(export tbl init-tbl)
(import (rnrs))
(define tbl (make-eq-hashtable))
(define (init-tbl)
(hashtable-set! tbl 'a 10)
(hashtable-set! tbl 'b 20)
(hashtable-set! tbl 'c 30)))
Is it considered bad form to take the first approach? I.e. to have a library which also executes arbitrary expressions? Are there drawbacks to this approach?
A related issue... In a library, non-definition expressions must occur after definitions. To work around this constraint, I'm using this macro:
(define-syntax no-op-def
(syntax-rules ()
((_ expr ...)
(define no-op
(begin
expr
...)))))
for example:
(define t0 (make-eq-hashtable))
(no-op-def
(hashtable-set! t0 'a 10))
(define t1 (make-eq-hashtable))
(no-op-def
(hashtable-set! t1 'b 20))
Again, are there drawbacks to interspersing expressions and definitions via this workaround?