4 ms·
does this mean that you can't do `eval`-like things in "production" systems?
by rtpg 2mo ago
does this mean that you can't do `eval`-like things in "production" systems?
- p_l 2mo agoIIRC not compiled (you can include the interpreter). But then Scheme was always less EVAL-friendly of the lisps
- shakna 2mo agoI'm not seeing the less friendly... Eval, and sandboxing eval, are builtin features of the Scheme standard.
- bandrami 2mo agoIt has eval but it lacks reader macros (or at least it did thirty years ago) which is what makes eval useful on lisp2 systems.
- floxy 2mo agoI'm interested in reading more about how reader macros make `eval` better/useful.
- shakna 2mo agoR5RS supports reader macros? Which would be 1998, and I guess only 28 years ago. That's why SRFI-49 and its descendants were a possibility. Wisp, JavaScript, brainfuck, etc. implementations all exist because the tools exist in the language.
- jeandrek 2mo agoIt does not. https://conservatory.scheme.org/schemers/Documents/Standards/R5RS/HTML/r5rs-Z-H-5.html#%_chap_2 https://conservatory.scheme.org/schemers/Documents/Standards... Particular implementations could.
- shakna 2mo agoThat document, shows several forms: https://conservatory.scheme.org/schemers/Documents/Standards/R5RS/HTML/r5rs-Z-H-10.html#%_sec_7.3 https://conservatory.scheme.org/schemers/Documents/Standards...
- jeandrek 2mo agoCommon Lisp reader macros hook into the reader itself as it's parsing S-exps and meets some character combination: http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/glo_r.html#reader_macro http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec... Define-syntax is for making special forms (i.e. normal macros). Not that I know why eval should be paired with reader macros.
- deleted 2mo ago[deleted]
- jeandrek 2mo agoThe 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.