3 ms·
Scheme 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'
by shakna 2mo ago
Scheme 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.