On Jun 14, 2009, at 2:38 PM, Ramana Kumar wrote:

All right. Maybe you can suggest how you would do this (portably). I
have a script full of tests for various versions of a library (and
these versions are in flux). Different versions export different
subsets of the set of all possible exports for this library. I'd like
to be able to run the test script on a particular version and have it
figure out which tests are applicable and run them, with minimal
effort (e.g. just changing a library name in the test script, or even
passing it in on the command line).

Mark each test with the set of identifiers it requires and wrap it
with (when-bound (id) <test-expr>) and use the "when-bound" definition
below.  I tried it in many examples and Ikarus, Larceny, and PLT agree
on everything I tried while ypsilon did not. Use it as a starting point.

Aziz,,,

[PS. Fujita reads the list, so, he might shed some light for why ypsilon
is behaving differently.]

$ cat /tmp/t.ss

#!r6rs
(import (rnrs))

(define-syntax when-bound
  (lambda (x)
    (syntax-case x ()
      [(ctxt (id) e* ...)
       (let ([t (car (generate-temporaries '(t)))])
         (if (free-identifier=? #'id
                (datum->syntax t (syntax->datum #'id)))
             #'(begin)
             #'(begin e* ...)))])))

(when-bound (let)
  (display "let is bound\n"))

(when-bound (foo)
  cannot happen)

(define-syntax q1
  (syntax-rules ()
    [(_)
     (begin
       (define q1 12)
       (when-bound (q1) (display "q1 is bound\n")))]))
(q1)

(define-syntax q2
  (syntax-rules ()
    [(_ q2)
     (begin
       (define q2 12)
       (when-bound (q2) (display 'q2) (display " is bound\n")))]))

(q2 quux)

(define-syntax q3
  (syntax-rules ()
    [(_ q3 q4)
     (begin
       (define q3 12)
       (when-bound (q4) (display 'q4) (display " is bound\n")))]))

(q3 quux1 quux1)
(q3 quux2 quux3)

$ ikarus --r6rs-script /tmp/t.ss
let is bound
q1 is bound
quux is bound
quux1 is bound

$ plt-r6rs /tmp/t.ss
let is bound
q1 is bound
quux is bound
quux1 is bound

$ larceny -r6rs -program /tmp/t.ss
let is bound
q1 is bound
quux is bound
quux1 is bound

$ ypsilon --r6rs /tmp/t.ss
q1 is bound


Reply via email to