[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Export utility
It turns out that a reasonable export utility is very easy to write.
For those who are interested, here it is...
Usage:
(EXPORT TO-ENV FROM-ENV SYMBOL)
Defines SYMBOL in TO-ENV in such a way that it has exactly the
same definition as it does in FROM-ENV, except that if you
later SET or BIND SYMBOL in TO-ENV, this will not affect its
definition in FROM-ENV. EXPORT will work so long as SYMBOL is
bound (in FROM-ENV) to what T consider's to be a value or if
SYMBOL is an entry in FROM-ENV's syntax table.
(EXPORT TO-ENV FROM-ENV LIST-OF-SYMBOLS)
As above, except all the symbols in the list are exported.
The T code:
(define (%export to-env from-env ident)
(set ident (check-arg symbol? ident export))
(cond ((syntax-table-entry (env-syntax-table from-env) ident)
=> (lambda (syntax)
(set (syntax-table-entry (env-syntax-table to-env) ident)
syntax)
ident))
((env-lookup from-env ident nil nil)
=> (lambda (loc) (*define to-env ident (contents loc)) ident))
(t (%export to-env from-env
(error "identifier ~a unknown in ~a" ident from-env)))))
(%export *system-env* *t-implementation-env* 'environment?)
(define (export to-env from-env identifiers)
(set to-env (check-arg environment? to-env export))
(set from-env (check-arg environment? from-env export))
(if (list? identifiers)
(map (lambda (sym) (%export to-env from-env sym)) identifiers)
(%export to-env from-env identifiers)))
Comments:
I've tried to restrict the defintion of EXPORT and %EXPORT to released
T functions. This was not entirely possible as ENV-LOOKUP does not
do arg checking, and its implementation is such that if it gets a
non-environment the resulting error will provide no useful info as
to what happened. The function ENVIRONMENT? is needed to perform
the indicated arg checking, but it has not yet been released to
*SYSTEM-ENV*.
At the moment, the restrictions on use of things from
*T-IMPLEMENTATION-ENV* means that %EXPORT is not as efficient as it
could be. The way it's set up, if the object being exported is a
value (i.e., not syntax), then %EXPORT must look for SYMBOL in FROM-ENV
twice. This could be fixed, but %EXPORT might break if the
implementation ever changed significantly. On the other hand, this
definition should be stable.
==========
Someone feel like installing this in t_utils? Or, will the T
implementors release an export function?