klipse

Yehonathan Sharvit 2016-10-29T15:34:52.000222Z

@jrheard I was off for the week end

Yehonathan Sharvit 2016-10-29T15:44:22.000224Z

@jrheard your blog post is wonderful!

Yehonathan Sharvit 2016-10-29T15:44:38.000225Z

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

Yehonathan Sharvit 2016-10-29T15:51:18.000226Z

regarding infinite loops

Yehonathan Sharvit 2016-10-29T15:51:46.000227Z

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

Yehonathan Sharvit 2016-10-29T15:52:01.000228Z

do you know how figwheel prevents infinite loops

Yehonathan Sharvit 2016-10-29T15:52:18.000229Z

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

Yehonathan Sharvit 2016-10-29T16:17:18.000231Z

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

Yehonathan Sharvit 2016-10-29T16:17:22.000232Z

very cool!

jrheard 2016-10-29T16:26:20.000233Z

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

jrheard 2016-10-29T16:26:26.000234Z

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

jrheard 2016-10-29T16:27:13.000235Z

also glad that :simple worked

jrheard 2016-10-29T16:27:46.000236Z

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

jrheard 2016-10-29T16:28:45.000237Z

(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 Sharvit 2016-10-29T16:29:11.000238Z

I’m thinking of another hack to prevent infinite loops

Yehonathan Sharvit 2016-10-29T16:29:16.000239Z

are u ready?

jrheard 2016-10-29T16:29:18.000240Z

sure man

Yehonathan Sharvit 2016-10-29T16:29:45.000241Z

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

Yehonathan Sharvit 2016-10-29T16:29:52.000242Z

Intercepting all js function calls

jrheard 2016-10-29T16:29:59.000243Z

ha

Yehonathan Sharvit 2016-10-29T16:30:06.000244Z

by overrriding Function.prototype.call

jrheard 2016-10-29T16:30:10.000245Z

interesting!

jrheard 2016-10-29T16:30:20.000247Z

i wonder what that would do to performance, hm

jrheard 2016-10-29T16:30:30.000248Z

can’t know unless we try, i guess!

jrheard 2016-10-29T16:30:32.000249Z

what would guard() do?

Yehonathan Sharvit 2016-10-29T16:30:56.000250Z

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

jrheard 2016-10-29T16:31:11.000251Z

gotcha

Yehonathan Sharvit 2016-10-29T16:31:17.000252Z

do u think it can work?

jrheard 2016-10-29T16:31:40.000253Z

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

Yehonathan Sharvit 2016-10-29T16:32:13.000254Z

ok

jrheard 2016-10-29T16:35:34.000255Z

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;
  }
}

jrheard 2016-10-29T16:37:43.000259Z

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

jrheard 2016-10-29T16:38:16.000260Z

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

jrheard 2016-10-29T16:38:36.000261Z

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

Yehonathan Sharvit 2016-10-29T16:40:19.000265Z

there is this line

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

Yehonathan Sharvit 2016-10-29T16:40:31.000266Z

Maybe there is a way in js to hook new

jrheard 2016-10-29T16:40:51.000267Z

ah, good point!

jrheard 2016-10-29T16:41:15.000268Z

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

jrheard 2016-10-29T16:41:22.000269Z

so there’s your function call!

Yehonathan Sharvit 2016-10-29T16:41:31.000270Z

not sure

Yehonathan Sharvit 2016-10-29T16:41:38.000271Z

let’s check

jrheard 2016-10-29T16:41:40.000272Z

and also the cljs.core.eq call

Yehonathan Sharvit 2016-10-29T16:41:51.000273Z

yeah!

Yehonathan Sharvit 2016-10-29T16:41:56.000274Z

very good point

Yehonathan Sharvit 2016-10-29T16:42:04.000275Z

there will always be a function call somewhere

jrheard 2016-10-29T16:42:37.000276Z

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!

Yehonathan Sharvit 2016-10-29T16:42:47.000277Z

yeah

Yehonathan Sharvit 2016-10-29T16:42:50.000278Z

I’m gonna try

Yehonathan Sharvit 2016-10-29T16:42:51.000279Z

it

jrheard 2016-10-29T16:42:53.000280Z

nice 😄 gl!

Yehonathan Sharvit 2016-10-29T16:43:02.000281Z

BTW, there is a much cleaner solution

jrheard 2016-10-29T16:43:12.000282Z

do tell!

Yehonathan Sharvit 2016-10-29T16:44:16.000283Z

to hook the js compiler

jrheard 2016-10-29T16:44:24.000286Z

oh nice

jrheard 2016-10-29T16:44:41.000288Z

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

jrheard 2016-10-29T16:44:58.000289Z

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

Yehonathan Sharvit 2016-10-29T16:46:19.000290Z

Do you know how could I override this defmethod https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/compiler.cljc#L919

jrheard 2016-10-29T16:48:21.000293Z

it looks like if you just define a defmethod with the same signature after the first has been defined/imported, you should be good to go - http://app.klipse.tech/?cljs_in=(defmulti%20foo%20%3Abar)%0A%0A(defmethod%20foo%201%20%5Bthing%5D%20%22hello%22)%0A%0A(print%20(foo%20%7B%3Abar%201%7D))%0A%0A(defmethod%20foo%201%20%5Bthing%5D%20%22sup%22)%0A%0A(print%20(foo%20%7B%3Abar%201%7D))

jrheard 2016-10-29T16:49:10.000294Z

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

jrheard 2016-10-29T16:52:35.000295Z

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

Yehonathan Sharvit 2016-10-29T16:52:47.000296Z

np

Yehonathan Sharvit 2016-10-29T16:52:52.000297Z

enjoy your breakfast

Yehonathan Sharvit 2016-10-29T20:12:01.000298Z

@jrheard I somehow solved the infinite loop issue

Yehonathan Sharvit 2016-10-29T20:12:15.000299Z

by hooking the cljs compiler emits function

jrheard 2016-10-29T20:12:46.000300Z

!!!!!!

jrheard 2016-10-29T20:12:50.000301Z

that’s awesome!

Yehonathan Sharvit 2016-10-29T20:13:06.000302Z

Could you please review my code here https://github.com/viebel/klipse/pull/131 ?

jrheard 2016-10-29T20:13:17.000304Z

absolutely

Yehonathan Sharvit 2016-10-29T20:13:28.000305Z

Take a look at the playground-dbg test page

Yehonathan Sharvit 2016-10-29T20:13:46.000306Z

I inserted a guard on if and continue

Yehonathan Sharvit 2016-10-29T20:14:02.000307Z

if is generted by the emit :if function

Yehonathan Sharvit 2016-10-29T20:14:17.000308Z

continue is generated by emit :recur

jrheard 2016-10-29T20:14:47.000309Z

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

Yehonathan Sharvit 2016-10-29T20:14:51.000310Z

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

Yehonathan Sharvit 2016-10-29T20:15:25.000312Z

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

Yehonathan Sharvit 2016-10-29T20:15:31.000313Z

take your time to review

Yehonathan Sharvit 2016-10-29T20:15:52.000314Z

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

jrheard 2016-10-29T20:16:02.000315Z

sounds great

Yehonathan Sharvit 2016-10-29T20:16:12.000316Z

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

Yehonathan Sharvit 2016-10-29T20:16:23.000317Z

but first: what’s your name

jrheard 2016-10-29T20:16:25.000318Z

hee

jrheard 2016-10-29T20:16:28.000319Z

my name’s JR Heard, easy 🙂

Yehonathan Sharvit 2016-10-29T20:16:32.000320Z

but let’s move to private

jrheard 2016-10-29T20:16:39.000321Z

sure

2016-10-29T22:10:44.000323Z

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 Sharvit 2016-10-29T22:11:18.000325Z

what do u want to do exactly @ghufran ?

2016-10-29T22:13:59.000326Z

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 Sharvit 2016-10-29T22:14:30.000327Z

checking...

Yehonathan Sharvit 2016-10-29T22:39:05.000328Z

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