klipse icon indicating copy to clipboard operation
klipse copied to clipboard

Common Lisp side effects happen on each keystroke

Open phoe opened this issue 6 years ago • 7 comments

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.

phoe avatar May 07 '18 13:05 phoe

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.

davazp avatar May 07 '18 16:05 davazp

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.

phoe avatar May 07 '18 16:05 phoe

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.

davazp avatar May 07 '18 16:05 davazp

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!

phoe avatar May 07 '18 16:05 phoe

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:

  1. add new functionality to Klipse: add a button to each Klipse snippet and do not evaluate the code until the read clicks the button
  2. 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.

viebel avatar May 08 '18 14:05 viebel

I suggest 1) with Ctrl+Enter being a shortcut for evaluation.

phoe avatar May 08 '18 14:05 phoe

Ctrl-Enter already works. You cannot really feel it because the evaluation delay is too short (40ms)

viebel avatar May 08 '18 14:05 viebel