[gambit-list] Some questions about reader in Gambit

Per Eckerdal per.eckerdal at gmail.com
Sun Dec 13 18:49:27 EST 2009


I haven't hacked around very much with the readtable of Gambit, but this might at least help guide you in a somewhat right direction:

> 2. Do interpreter and compiler use same method of file reading?
>   Same readtable?

I'm quite sure that it uses pretty much the same reader, but it's very possble that the readtable objects are not the same. ##current-readtable seems to be a relevant thing.

> 3. Qi constructions after Qi-reader are just like scheme ones, but
> before they are often different. For instance:
> Qi: [ A B | C ]
> after qi-reader:
> (cons A (cons B (cons C ())))
> How can I integrate Qi reader into Gambit to slightly transform input
> with minimal effort?

This should be easy. What you want to do is to make a standard readtable, possibly with (##make-standard-readtable), and modify it with ##readtable-char-class-set!. It basically allows you to take over the parsing on certain characters. Search for the use of that function in Gambit's source. _io.scm contains most of it I think. You would want to imitate the function that handles the character (.

I would probably develop the Qi readtable object entirely using Gambit syntax, testing that read works properly in isolation, but avoiding letting it take over the REPL as I code. A utility function similar to this might be useful:

(define (with-readtable readtable thunk)
  (let* ((p (current-input-port))
         (old-rt (input-port-readtable p)))
    (dynamic-wind
        (lambda ()
          (input-port-readtable-set! p readtable))
        thunk
        (lambda ()
          (input-port-readtable-set! p old-rt)))))

(with-readtable [qi-readtable] read)

/Per




More information about the Gambit-list mailing list