Hi, Marc!
During last three days I am porting Qi (http://en.wikipedia.org/wiki/Qi_%28programming_language%29) to Gambit. qiYACC, qiReader, qiEval, qiCore are already ported, next will be qiProlog and Qi type checking machinery. And it will be cool if I integrate Qi reader with Gambits one.
And there are some questions: 1. Could you please in two words explain source-location data? 2. Do interpreter and compiler use same method of file reading? Same readtable? 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?
Vasil
Afficher les réponses par date
- Could you please in two words explain source-location data?
Check lib/_eval.scm
Example:
(##define-syntax compile-time (lambda (stx) (##sourcify-deep (apply (lambda (_macroname . body) (eval `(begin ,@body))) (##source-code stx)) stx)))
- Do interpreter and compiler use same method of file reading?
Same readtable?
Dunno.
- 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?
Dunno. The first question would be, how is the Qi reader written in the original implementation?
Christian.
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:
- 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.
- 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