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

Introspection



I'm sending this message to this mailing list because many Scheme
implementors are on it...  sorry if this message does not interest you.

I'm trying to design a "portable" function to determine at run-time
the implementation (Gambit, Chez-Scheme, Bigloo, etc) that is running
the code (how's that for a paradox!).  I've come up with the function
below, which checks for small differences in the reader.  It is able
to distinguish between the following implementations:

  Gambit, SCM, STk, MIT-Scheme, Scheme->C, Chez-Scheme, Elk, Bigloo

Unfortunately it doesn't work on all implementations (e.g. scheme48, scsh)
because it is not completely R4/5RS compliant syntactically.

Could anyone suggest some other feature of the language that could be
checked using syntactically valid code yet would yield different
results on different implementations.

(define (scheme-system)
  (let ((str1 (symbol->string 'aB\c\D))
        (str2 "\0411\x23"))
    (cond ((equal? str1 "aB\\c\\D")
           'gambit) ; Gambit in case-sensitive mode
          ((equal? str1 "ab\\c\\d")
           (let* ((c0 (string-ref str2 0)))
             (cond ((char=? c0 (integer->char 0))
                    'scm)
                   ((char=? c0 (integer->char 9))
                    'stk)
                   ((char=? c0 #\!)
                    (cond ((char=? (string-ref str2 2) #\#)
                           'gambit) ; Gambit in case-insensitive mode
                          (else
                           'mit)))
                   (else
                    'unknown))))
          ((equal? str1 "ABcD")
           'scheme-to-c)
          ((equal? str1 "abcD")
           'chez)
          ((equal? str1 "aBcD")
           'elk)
          ((equal? str1 "AB\\C\\D")
           'bigloo)
          (else
           'unknown))))