[plt-scheme] ifndef in PLT?

From: Eli Barzilay (eli at barzilay.org)
Date: Fri Oct 7 14:24:26 EDT 2005

On Oct  7, Dmitry Lizorkin wrote:
> Well, as far as I understand, the built-in support for
> `string-upcase' and `string-downcase' was introduced to mzscheme
> since PLT v. 299.200. I have a piece of code that uses these
> functions and that has to work for PLT versions [204, the latest
> one]. Since PLT module system prohibits multiple definitions of an
> identifier, I thus have to not-define `string-upcase' and
> `string-downcase' if they are already defined - and provide their
> definition otherwise.

Here's some code that should be easy to extend

(module compat mzscheme
  (provide *string-upcase *string-downcase)
  (define v300? (identifier-binding #'path->string))
  (define-values (*string-upcase *string-downcase)
    (if v300?
      (values (dynamic-require 'mzscheme 'string-upcase)
              (dynamic-require 'mzscheme 'string-downcase))
      (let ([with-copy (lambda (str-op!)
                         (let ([str-op! (dynamic-require '(lib "string.ss")
                                                         str-op!)])
                           (lambda (str)
                             (let ([str (string-copy str)])
                               (str-op! str)
                               str))))])
        (values (with-copy 'string-uppercase!)
                (with-copy 'string-lowercase!))))))

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.