aboutsummaryrefslogtreecommitdiff
path: root/tutorial/README.md
diff options
context:
space:
mode:
authorAndrey Popp <8mayday@gmail.com>2022-03-13 23:26:51 +0300
committerAndrey Popp <8mayday@gmail.com>2022-03-13 23:26:51 +0300
commite31ed99a5df67af7e80c8694c1d9ad5170c328f2 (patch)
tree417cb22f9abe3e97110339f57aba0464a161bc6a /tutorial/README.md
parentf036d93326170963e69cba2f652811d6dcab81dd (diff)
Add repl preview
Repl now has an additional mode of evaluation where observable (visible outside of the evaluated expression) side effects are not allowed. More specifically all assignments and reassignments are *prohibited* unless they fall in the following categories: - Assignments and reassignments within the top level environment - Assignments and reassignments for the environments created during evaluation of the expression being previewed Examples: let repl = BQN.makerepl() repl.preview('42') // ok, pure repl.preview('x ← 42 ⋄ x + 1') // ok, x is from the top env repl('f ← {x ← 0 ⋄ F ← {x+↩𝕩} ⋄ f}') repl.preview('F 42') // fail! mutates x How it's implemented: - A global `preview` flag determines if we are in "preview" mode - During compilation of bytecode to JS we inject code which marks environments with `inpreview` flag - `true` means they've been created during "preview". - Top level environment always has `inpreview = true` as we have this handled by restoring it to the values before the "preview" eval started. - While setting variables we check if are in "preview" and if the target environment has `inpreview` flag, otherwise we fail.
Diffstat (limited to 'tutorial/README.md')
0 files changed, 0 insertions, 0 deletions