On Tue 03 Jan 2012 11:52, Mark H Weaver <m...@netris.org> writes: > +(define-record-type lexical-environment-type > + (make-lexical-environment wrapper names boxes others module-name) > + lexical-environment? > + (wrapper lexenv-wrapper) > + (names lexenv-names) > + (boxes lexenv-boxes) > + (others lexenv-others) > + (module-name lexenv-module-name))
Why a module-name and not a module? > +(define-syntax-rule (box v) > + (case-lambda > + (() v) > + ((x) (set! v x)))) This is nice. If you want to make a hack, you can get at the variable object here, using program-free-variables. It is fairly well guaranteed to work. Dunno if it is needed, though. > +(define-syntax-rule (box-lambda* (v ...) (other ...) e) > + (lambda (v ...) > + (let-syntax > + ((v (identifier-syntax-from-box v)) > + ... > + (other (unsupported-binding 'other)) > + ...) > + (if #t e)))) I would fix the indentation here. What's the purpose of the (if #t e) ? > +(define-syntax-rule (capture-environment > + module-name (v ...) (b ...) (other ...)) > + (make-lexical-environment > + (lambda (expression) > + #`(box-lambda* > + #,'(v ...) Why not just (v ...) ? > + #,'(other ...) Likewise. And again, the indentation :) > +(define-syntax-rule (identifier-syntax-from-box b) > + (let ((trans (identifier-syntax > + (id (b)) > + ((set! id x) (b x))))) > + (set-procedure-property! trans > + 'identifier-syntax-box > + (syntax-object-of b)) > + trans)) Ew, identifier-syntax as a value :) But OK. > +;; XXX The returned syntax object includes an anti-mark > +;; Is there a good way to avoid this? > +(define-syntax syntax-object-of > + (lambda (form) > + (syntax-case form () > + ((_ x) #`(quote #,(datum->syntax #'x #'x)))))) This has a bad smell. Anything that is outside psyntax should not have to think about marks. Perhaps syntax-local-value could serve your purpose? > + (global-extend 'core 'the-environment This one is really nasty, and I'd like to avoid it if possible. Are there some short primitives that psyntax could export that would make it possible to implement `the-environment' in a module? It seems to me that some primitive to return a list of all syntax objects visible at a given point of a program, together with a primitive to retrieve the module that corresponds to a syntax object, could be sufficient. WDYT? > static void > +test_scm_local_eval () Thanks for going all the way with documentation and test cases. This is great. Cheers, Andy -- http://wingolog.org/