[gambit-list] environment

Mikael mikael.trash at gmail.com
Fri Mar 11 13:53:25 EST 2011

2011/3/11 spir <denis.spir at gmail.com>

> Hello,
> Is an environment implemented as plain Scheme data?

> If yes, is the current
> environment (I mean the set of currently "lookup-able" symbols) accessible?


> Hope I'm clear (don't know yet Scheme's proper vocabulary yet). I'm
> thinking at
> something along the lines of:
>     (getSymbolValue env 'a)
> beeing equivalent, for a symbol 'a, to:
>     (eval 'a)

Gambit has only one environment. It has several namespaces though. The REPL
default namespace has the name "~".

Implement this as:
(define (getSymbolValue sy) (eval (string->symbol (string-append "~#"
(symbol->string sy))))

> and
>     (defSymbol env 'a 1)
> equivalent to:
>     (define a 1)

Someone knows this one better than me.

Maybe experiment with (define (defSymbol sy value) (eval `(define
,(string->symbol (string-append "~#" (symbol->string sy)) ,value)))) but no

Since it's lisp generally you'd spell out the above rather as
get-symbol-value and def-symbol! .

Aside pure reflexivity, this would allow some nice tricks, like unpaking an
> associative table into the current env:
>     (unpack (parseRecord line))
> where parseRecord returns eg a (name phone email) table, would def symbols
> under those names in env.

Generally you want to avoid using the global namespace as much as you ever
can. You want to use it only as a trampoline for the real work you do. One
of the few things you really need to keep there are [library/module]
procedures etc. that you intend to reuse over and over.


> --
> _________________
> vita es estrany
> spir.wikidot.com
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://webmail.iro.umontreal.ca/pipermail/gambit-list/attachments/20110311/3308238d/attachment.html 

More information about the Gambit-list mailing list