4 ms·
The less-eval-friendly thing is R5RS only requires two possible "environment specifiers" (2nd arg to eval), returned by SCHEME-REPORT-ENVIRONMENT and NULL-ENVIR
by jeandrek 2mo ago
The less-eval-friendly thing is R5RS only requires two possible "environment specifiers" (2nd arg to eval), returned by SCHEME-REPORT-ENVIRONMENT and NULL-ENVIRONMENT, with no special form or procedure to get the current lexical environment; and R4RS (I just checked) does not specify eval. There's pretty much no manipulation of environments in the standard; the best is something like
((eval `(lambda (foo) ,exp) (scheme-report-environment 5))
foo)
(can't really think of applications for getting the current environment right now except for pseudo-macro stuff)
- shakna 2mo agoScheme is hygeneic, yes. Which is why sandboxing works. If you want to manipulate the current environment, and defeat half the point of the language, then you're allowed that through (user-initial-environment). (define-syntax) will also let you rewrite the bindings however you require. Edit: Here's an eval macro I use fairly often: (define-syntax constexpr (syntax-rules () ((_ expr) (begin (syntax->datum (datum->syntax (quote-syntax here) (eval 'expr (interaction-environment)))))))) (define (factorial n) (if (<= n 1) 1 (* n (factorial (- n 1))))) (define n (constexpr (factorial 10)))
- jeandrek 2mo agoBy the current lexical environment I meant the lexical environment at some place in the code (not just the top-level one, which user-initial-environment gives, though it's optional). I'm not attempting to make a case for anything; but without that RnRS' eval doesn't grant more expressivity than just tacking on an interpreter to every program, which you could also just do yourself. (It also doesn't complicate the implementation; variable names don't need to be preserved after compiling.) I.e. it makes sense to say standard Scheme has been less "eval-friendly," even if there were good reasons or one doesn't care.