[plt-scheme] quasiquote confusion with printable<%> interface

From: Todd O'Bryan (toddobryan at gmail.com)
Date: Wed Dec 9 08:04:17 EST 2009

I'm trying to use the class system to model database fields. I'm
implementing the printable<%> interface, but weirdness is occurring.

Here's the Field% class:

(define Field%
  (class* object% (printable<%>)
     [backend (new DatabaseBackend%)])


    (define/public (custom-write port)
      (write `(new Field% [name ,(send backend quote-name name)]) port))

    (define/public (custom-display port)
      (display (format "Field%: ~a" name) port))))

and when I create and write a Field%, everything works as expected.

> (define f (new Field% [name "blah"]))
> f
(new Field% (name "\"blah\""))

Here's a CharField%:

(define CharField%
  (class Field%
    (inherit-field backend, name)


    (define/override (custom-write port)
      (write `(new CharField%
                   [name ,(send backend quote-name name)]
                   [max-length ,max-length]) port))))

But when I try to create and write a CharField%, the unquote seems to
be ignored.

> (define cf (new CharField% [name "blah"] [max-length 20]))
> cf
(new CharField% (name ,(send backend quote-name name)) (max-length ,max-length))

What am I doing wrong?

Posted on the users mailing list.