klipse

jrheard 2016-10-28T01:52:28.000156Z

opened https://github.com/viebel/klipse/pull/129

jrheard 2016-10-28T02:41:18.000158Z

@viebel - one thing i’ve run into while messing around with klipse snippets is that it’s easy to completely murder a browser tab if, while editing a snippet’s code, you accidentally make it infinite loop

jrheard 2016-10-28T02:41:27.000159Z

have you run into this before / do you think it’s possible to fix?

jrheard 2016-10-28T03:39:08.000161Z

signing off for the night (utc-7 🙂 ), later!

Yehonathan Sharvit 2016-10-28T03:39:34.000162Z

@jrheard your code looks great

Yehonathan Sharvit 2016-10-28T03:39:37.000163Z

will test it later

Yehonathan Sharvit 2016-10-28T03:39:52.000164Z

I’m aware of the infinite loop issue

Yehonathan Sharvit 2016-10-28T03:40:20.000165Z

1. I was expecting the browser to detect it and stop the script

Yehonathan Sharvit 2016-10-28T03:40:55.000166Z

2. I mitigated it by limiting the print-length of the ouptut to 1000 (configurable) so that (range) is not crashing

Yehonathan Sharvit 2016-10-28T03:42:32.000167Z

3. Someone tried to solve it by wrapping all the recur statements after macro expansion. It looks interesting. It’s here: https://github.com/oakes/eval-soup/blob/master/src/eval_soup/core.cljs#L86-L92. But it has some limitation: https://github.com/oakes/eval-soup/issues/1

Yehonathan Sharvit 2016-10-28T03:42:45.000169Z

4. Do you have any ideas of your own?

Yehonathan Sharvit 2016-10-28T06:36:20.000170Z

@jrheard I’ve merged your code and deployed it - KLIPSE version 4.4.0

😄 1
Yehonathan Sharvit 2016-10-28T06:36:23.000171Z

Thanks a lot

Yehonathan Sharvit 2016-10-28T06:36:41.000172Z

Now, I’m waiting for your blog past with the canvas stuff

jrheard 2016-10-28T07:05:58.000173Z

nice, thanks!

jrheard 2016-10-28T07:06:04.000174Z

i was thinking a timeout like figwheel’s repl’s might be a good solution

jrheard 2016-10-28T07:06:13.000175Z

with a shorter timeout, like 2 seconds max instead of figwheel’s 8

jrheard 2016-10-28T07:06:20.000176Z

haven’t looked into feasibility

jrheard 2016-10-28T07:07:59.000177Z

will read cljs-soup in the morning, looks like it also does timeouts

jrheard 2016-10-28T07:08:20.000178Z

expect the post early next week 😄

jrheard 2016-10-28T07:08:44.000179Z

it’s not very complicated but i need to finish setting up my blog / etc

jrheard 2016-10-28T07:08:49.000180Z

ok sleeptime

jrheard 2016-10-28T16:00:16.000185Z

dang, i guess it just plain isn’t possible to kill a running function in js

jrheard 2016-10-28T16:01:39.000186Z

http://stackoverflow.com/questions/17007482/how-can-i-interrupt-and-stop-a-running-function-in-javascript suggests webworkers, but you can’t touch the DOM from those, and i like being able to touch the DOM in klipse

jrheard 2016-10-28T16:03:46.000188Z

so, i’m out of ideas 🙂

jrheard 2016-10-28T17:28:29.000189Z

i came up with a hacky idea

jrheard 2016-10-28T17:28:31.000190Z

i’m not sure if i like it

jrheard 2016-10-28T17:29:00.000191Z

but if it’s possible to run cljs code in the context of web workers - and i haven’t checked to see if it is - you could use them as a sort of canary

jrheard 2016-10-28T17:29:42.000192Z

so at snippet evaluation time, each klipse snippet could spin up a web worker, let it execute for up to two seconds, and if it hasn’t executed by then you know the snippet’s code will time out, so you can kill the web worker and not execute the snippet’s code in the main js thread, and show an error message in the output codemirror window

jrheard 2016-10-28T17:30:17.000193Z

and if the web worker executes successfully within two seconds (i don’t know anything about web workers but i’m guessing that there’s a way to be notified if the worker completes much earlier, eg after only 5ms or something), you can be relatively sure that the code is safe to run, and so then the snippet goes ahead and runs its cljs code in the context of the main js thread

jrheard 2016-10-28T17:30:35.000194Z

the main obvious badness of this “solution” is that every snippet ends up being run twice per evaluation

jrheard 2016-10-28T17:30:44.000195Z

and so if it has side effects, that’s bad; and if the code it contains is very slow, then it will be twice as slow as it would have been otherwise

jrheard 2016-10-28T17:31:10.000196Z

on the other hand, again i don’t know anything about web workers but i’ve heard that they can’t manipulate the DOM, so that’s a whole category of side effect that we don’t have to worry about duplicating

jrheard 2016-10-28T17:31:27.000197Z

anyway this idea is probably bad, but i figured i’d mention it in case it can serve as a jumping-off point for better solutions

jrheard 2016-10-28T17:49:12.000202Z

does klipse_plugin.min.js not work for clojure? i notice that it’s not listed in the clojure example of https://github.com/viebel/klipse , and i’ve had some trouble getting it to work for me

jrheard 2016-10-28T17:49:14.000204Z

gonna try again

jrheard 2016-10-28T17:50:49.000206Z

i get this error:

DOMException: Failed to execute 'querySelectorAll' on 'Document': The provided selector is empty.
    at Ay (<http://app.klipse.tech/plugin_prod/js/klipse_plugin.min.js:24664:25>)
    at By (<http://app.klipse.tech/plugin_prod/js/klipse_plugin.min.js:24668:10>)
    at <http://app.klipse.tech/plugin_prod/js/klipse_plugin.min.js:25488:1>
    at <http://app.klipse.tech/plugin_prod/js/klipse_plugin.min.js:25490:3>

jrheard 2016-10-28T18:19:36.000207Z

hm, right - is this because bootstrapped cljs isn’t compatible with advanced compilation?

jrheard 2016-10-28T18:19:54.000208Z

https://github.com/clojure/clojurescript/wiki/Optional-Self-hosting mentions being able to get up to :optimizations :simple

jrheard 2016-10-28T18:26:43.000210Z

the regular plugin build compiles fine if i switch it from :whitespace to :simple - would that be a good change to make?

jrheard 2016-10-28T18:27:05.000211Z

i see 8.1MB with the :whitespace build and 6.6MB with the :simple build

jrheard 2016-10-28T18:27:55.000212Z

(i know you’re in a different timezone and it’s the weekend, don’t worry, i’m not expecting immediate responses to any of these messages - just writing them down so i don’t forget these things 🙂 )

jrheard 2016-10-28T18:30:25.000213Z

it looks like the gzipped sizes are 1MB with :whitespace, 0.775MB with :simple

jrheard 2016-10-28T18:30:45.000214Z

so maybe it’s not a huge deal, that’s not an extremely drastic difference, just figured i’d check to see if there’s a good reason not to use :simple for the plugin build

jrheard 2016-10-28T19:15:22.000216Z

also, FYI, the twitter links at the bottom of http://blog.klipse.tech/clojure/2016/03/17/klipse.html seem to point to the wrong place

jrheard 2016-10-28T22:56:49.000219Z

ok, here’s the post (in my blog staging area, please don’t share this via social media / etc yet, it won’t be living here long-term): http://jrheard.com/blog-staging/procedural-dungeon-generation-drunkards-walk-in-clojurescript/ . will prob publish it on monday morning