[gambit-list] anyone has a good way for dealing with script clean up?
Christian Jaeger
christian at pflanze.mine.nu
Sat Apr 28 03:38:02 EDT 2007
dillo gimp wrote:
> hi
>
> anyone has a good way for dealing with script clean up?
> I'm mostly writing programs in interpreted mode,
> ie, with a lot of redundant defines.
> when I try to compile an interpreted program (assuming it's entirely correct),
> the only problem while compiling with gsc is the redundant defines.
>
You mean, you have several defines of the same (toplevel) names?
One could argue that the interpreted program isn't correct then in the
first place :). If you really want to change a toplevel binding while
the program is running, use set! instead of the second and subsequent
defines.
> is there a script that can automatically rewrite a program so that it
> can be compiled
> to produce the same result as interpreted.
>
I'm not aware of one but it would be easy enough to do. If you don't
mind loosing location information, just |read-all| the file and map (or,
cleaner, fold) over the list, while remembering which identifyers you've
already seen..
If you want to keep location information, you could use my cj-expr
module -- a chjmodule currently. I've been wanting to release my current
code for a long time now, maybe I'll get to it soon.
> Is there deeper issues besides renaming?
>
Renaming? What should be renamed and why? Hm do you mean you have code
like this?:
(define foo ...)
....use foo....
(define foo ...)
....use foo but always ever only the second one, never the first...
e.g. you're implicitely assuming scoping like this?:
(let ((foo ...))
....use foo...)
(let ((foo ...))
... use the second foo...)
Note that the toplevel define way really *overwrites* foo in the
interpreter, like set!, it doesn't create a new scope as is the case in
ML (well ML simply only has let iirc :)).
You better use explicit scoping then, either by putting both parts of
the program into separate namespaces:
(namespace ("firstpart#" foo))
(define foo ...)
....use foo....
(namespace ("secondpart#" foo))
(define foo ...)
....use foo but always ever only the second one, never the first,
except you could refer to the first by fully qualifying it: firstpart#foo
or by using let.
Christian.
More information about the Gambit-list
mailing list