Fork me on GitHub
#klipse
<
2016-10-29
>
Yehonathan Sharvit15:10:52

@jrheard I was off for the week end

Yehonathan Sharvit15:10:22

@jrheard your blog post is wonderful!

Yehonathan Sharvit15:10:38

It’s the first article featuring klipse that does graphics. Congrats

Yehonathan Sharvit15:10:18

regarding infinite loops

Yehonathan Sharvit15:10:46

the worker idea looks interesting but it makes the whole thing much more complicated and I’m not sure it worths it

Yehonathan Sharvit15:10:01

do you know how figwheel prevents infinite loops

Yehonathan Sharvit15:10:18

@bhauman how do you prevent infinite loops in figwheel repl?

Yehonathan Sharvit16:10:18

@jrheard thx for the :optimizations tip - I have deployed a smaller version of the plugin

jrheard16:10:20

glad you like the post! looking forward to publishing it 🙂

jrheard16:10:26

i agree with you that the worker idea is too complex for its own good

jrheard16:10:13

also glad that :simple worked

jrheard16:10:46

from what i can tell from using figwheel, i think that after 8 seconds, it returns control of the REPL to the user, but the function that timed out is still running

jrheard16:10:45

(when doing performance investigations / collecting simple benchmarks in intellij+cursive, i often send the figwheel repl functions that take 30 seconds or so to complete; after 8 seconds, the repl will say “evaluation timed out!” and allow me to run more commands, but 20 seconds later the results of my benchmarking function will appear in the repl’s output)

Yehonathan Sharvit16:10:11

I’m thinking of another hack to prevent infinite loops

Yehonathan Sharvit16:10:45

Function.prototype.call = function() { guard(); return window.cc.apply(this, arguments)}

Yehonathan Sharvit16:10:52

Intercepting all js function calls

Yehonathan Sharvit16:10:06

by overrriding Function.prototype.call

jrheard16:10:10

interesting!

jrheard16:10:20

i wonder what that would do to performance, hm

jrheard16:10:30

can’t know unless we try, i guess!

jrheard16:10:32

what would guard() do?

Yehonathan Sharvit16:10:56

guard = function(){
if (window.check) {
  var now = new Date();
  if ((now - start) > 1000) { window.check = false; throw("Infinite Loop")};}
}

Yehonathan Sharvit16:10:17

do u think it can work?

jrheard16:10:40

not sure! gonna poke around at something for a second, i wanna see if it would work on the specific infinite-loop i had, gonna see the generated js

jrheard16:10:34

so the main infinite-loop in my post’s code could be triggered if the user called drunkards-walk and asked for more empty cells to be carved out than actually exist on the grid, so eg (drunkards-walk 5 5 1000); i added a check to the start of the function to defend against this (sidenote: that check basically solves the problem for my purposes, so i’m less worried about the infinite loop issue than i was when i first asked about it) and so anyway i just looked at the generated js, and it looks basicaly like this:

var foo = 2, bar = 3, baz = 4;
while(true) {
  if(done(foo, bar, baz)) {
    return baz;
  } else {
  foo = foo+1;
  bar = bar+1;
  baz = baz+1;
  }
}

jrheard16:10:43

and so it’s not a situation where it’s a recursive function that keeps calling itself, it’s just this single function call that has a while(true) loop that will never be broken out of

jrheard16:10:16

i’m not sure if it’s possible to solve this particular case

jrheard16:10:36

unless the loop/recur solution in cljs-soup you linked a few days ago would solve this

Yehonathan Sharvit16:10:19

there is this line

var direction = new cljs.core.Keyword(null,”north","north",(651323902));

Yehonathan Sharvit16:10:31

Maybe there is a way in js to hook new

jrheard16:10:51

ah, good point!

jrheard16:10:15

i don’t think we have to worry about new, i think that ends up being a function call that’s just run with this bound to a specific value

jrheard16:10:22

so there’s your function call!

jrheard16:10:40

and also the cljs.core.eq call

Yehonathan Sharvit16:10:04

there will always be a function call somewhere

jrheard16:10:37

so yeah, if we muck with the value of function.prototype.call before the snippet’s code is run, and put back its old value afterward, then this could be a possible solution i think!

jrheard16:10:53

nice 😄 gl!

Yehonathan Sharvit16:10:02

BTW, there is a much cleaner solution

Yehonathan Sharvit16:10:16

to hook the js compiler

jrheard16:10:41

that sounds better, i was worried about effects that this could have on non-klipse code ont he page (analytics, ads, whatever)

jrheard16:10:58

so if it only affects the js generated by the snippet’s input cljs code, then that sounds good to me!

jrheard16:10:10

(there are probably edge cases / situations where this is unreliable, but at least it looks like it can be done)

jrheard16:10:35

ok, gonna have some breakfast and putter around and not check slack for a while 🙂 good luck!

Yehonathan Sharvit16:10:52

enjoy your breakfast

Yehonathan Sharvit20:10:01

@jrheard I somehow solved the infinite loop issue

Yehonathan Sharvit20:10:15

by hooking the cljs compiler emits function

jrheard20:10:50

that’s awesome!

jrheard20:10:17

absolutely

Yehonathan Sharvit20:10:28

Take a look at the playground-dbg test page

Yehonathan Sharvit20:10:46

I inserted a guard on if and continue

Yehonathan Sharvit20:10:02

if is generted by the emit :if function

Yehonathan Sharvit20:10:17

continue is generated by emit :recur

jrheard20:10:47

nice - might take me an hour or two to process this and play around with it, hope that’s ok 🙂

Yehonathan Sharvit20:10:51

the thing I don’t like is that I had to copy/paste the whole code of the original emits from the compiler

Yehonathan Sharvit20:10:25

I didn’t find a way to “wrap” it - but I’m sure it’s feasible

Yehonathan Sharvit20:10:31

take your time to review

Yehonathan Sharvit20:10:52

I’m not planning to deploy it without thorough testing anyway

jrheard20:10:02

sounds great

Yehonathan Sharvit20:10:12

May I ask you where do you work? How long are u into Clojure[script]

Yehonathan Sharvit20:10:23

but first: what’s your name

jrheard20:10:28

my name’s JR Heard, easy 🙂

Yehonathan Sharvit20:10:32

but let’s move to private

ghufran22:10:44

I saw this post about requiring and being able to use libraries in klipse: http://blog.klipse.tech/clojure/2016/03/29/klipse-clojure-libs.html Is there any way to require a library such as reagent to use in klipse?

Yehonathan Sharvit22:10:18

what do u want to do exactly @ghufran ?

ghufran22:10:59

Suppose I would like to go through the reagent tutorial: https://reagent-project.github.io/ If it was already set up using klipse, I could evaluate the code and change it right on the page. But if they haven’t done that, I would like to be able to copy and paste the code from the page into klipse and evaluate it there. However, I would need to be able to require the reagent library, is there any way to do this?

Yehonathan Sharvit22:10:05

It doesn’t work for the moment @ghufran because reagent is not self-host cljs friendly