klipse
klipse copied to clipboard
Common Lisp side effects happen on each keystroke
Following https://www.reddit.com/r/Common_Lisp/comments/8hlaoh/interactive_common_lisp_code_snippets_in_any_web/
Evaluating the forms at each single keystroke seems like a very bad idea. If I write a (DEFUN FOO (...) ...)
and then want to rename FOO
to FOOBARBAZQUX
, I do not want to define the functions named FOOB
, FOOBA
, FOOBAR
, ..., FOOBARBAZQUU
while I type. And this is the behaviour that is currently exhibited.
Should the code be evaluated in a fresh Lisp environment every time? I think it would make sense. You don't want old code to affect new code, not after every keypress or when you press a 'evaluate' button I would say.
I would prefer an option for explicit evaluation (perhaps a checkbox somewhere) along with an ability to trigger evaluation when hitting Ctrl+Enter
. This gives the programmer explicit control over when the evaluation should happen and the key chord is nonetheless fast enough to execute when someone is typing.
I think real-time compilation vs Ctrl+Enter
is an independent decision from what I suggested. Even with a button to evaluate the file it could make sense perhaps to evaluate everything in a fresh environment every time perhaps.
That being said, I'm not sure how easy/performant that would be on jscl.
Hmm. Creating a fresh environment for each single option would be viable, as long as it does not make typing inside the box sluggish.
The only way to figure it out is to test it!
Creating a fresh environment each time is not my preferred option as one of the value of Klipse is that you can share code between different code snippets on the same page.
There are a couple of possibilities here:
- add new functionality to Klipse: add a button to each Klipse snippet and do not evaluate the code until the read clicks the button
- configure Klipse on the page with a bigger delay before code evaluation is automatically triggered. Klipse's default is 40msec. It's configurable at the page level.
I suggest 1) with Ctrl+Enter being a shortcut for evaluation.
Ctrl-Enter
already works. You cannot really feel it because the evaluation delay is too short (40ms)