This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: Translators again
I> Suppose you have a clean translation -- something which tcl->scheme
> isn't
Hmm, why not? And what do you mean with "clean translation"?
> -- that is semantically identicle to Scheme but syntactically
> different. There's no reason you shouldn't be able to use that
> syntax in any environment. How do you force eval to use this
> new syntax in a Scheme environment?
May I use the module macros instead of raw environments?
--------------------------------------------------
;; the following module (== environment) translates
;; tcl into scheme code and executes it
;;
(module (lang tcl)
;; the following exports eval-string and repl with a tcl: prefix
(export (eval-string (alias tcl:eval-string) repl (alias (tcl:repl)) ...))
;; the following opens ice-9 guile and imports a number of symbols
(open ((ice-9 guile) define ...)))
(define (eval-string string) (eval (tcl->scheme string)) (the-environment))
(define (read) ...)
(define (eval r) ...)
(define (print e r) ...)
(define (repl) (print (eval (read))))
--------------------------------------------------
;; the following module tests the perl and tcl implementation
;;
(module (my string-fun)
;; the following imports all exported symbols from guile, tcl and perl
;; and renames guile's eval to system:eval
(open ((ice-9 guile) (rename eval system:eval)
((lang tcl))
((lang perl)))
(tcl:eval-string "1 + 1")
(perl:eval-string ""§!$!"§%"$%§$%!"§")) ;; or so ...
(define eval tcl:eval-string)
(eval "1 + 1)
(define (eval-language lang string)
(if (eqv? lang 'tcl) (tcl:eval ...) (perl:eval ...)))
--------------------------------------------------
> I guess I'm not clear enough about how environments would actually
> be used. In some ways a Tcl environment is a must, because of
> the dynamic scoping and all.
The tcl-eval-environment would be a normal eval environment
except that it exports a repl that a) reads expressions
b) translates them into guile's assembly language---scheme currently,
as guile doesn't have a byte code evaluator and c) executes the scheme
code.
You'll have to emulate dynamic scoping (with fluids?) as environments
can't help you further.
> eval definately *can't* dispatch on the first argument.
> (eval "(+ 1 2)") evaluates to "(+ 1 2)", after all.
Yep.
Jost