Fork me on GitHub
#clojurescript
<
2015-10-24
>
dvcrn03:10:39

@bensu @thheller I am using export already, but yeah as you said, for the module to get consumed by another node module export.xxxx = xxx has to be inside the file. On :simple this works great because it all compiles down into 1 file, but for debugging when using :none, the file that contains the export is not the one that gets consumed by node. That one is somewhere inside the out/ folder

dvcrn03:10:17

For now, I just leave it on :simple so my code works but was wondering if someone had to deal with this problem already

dvcrn03:10:16

to give context what I'm doing: in electron (the thing that githubs atom runs in), to be able to communicate from the frontend to the backend of the app, you need to use remote.require which is then just using a require inside the backend folder. That is afaik the only way to use backend functions inside the frontend and do things like opening file dialogs and what not. So I created a new cljsbuild target and use clojurescripts aset to manually export my file as a module: (aset js/exports "core" markright.core) - https://github.com/dvcrn/markright/blob/master/src_actions/markright/core.cljs#L35

thheller08:10:41

@dvcrn: this is node?

thheller08:10:49

ah electron ok

ul09:10:40

what is the best way to check if some var is defined in cljs? exists?? I want to define system-time in my code if user uses cljs version prioir that having system-time in core

ul09:10:14

but even better if it is possible compile-time

colin.yates09:10:35

@ul a really ugly way would be to invoke it in a try/catch….. yeah.

bensu09:10:08

@dvcrn: the frontend running on a browser like environment and the backend running on node, right? To communicate between boths there is also ipc. I've been developing with :none https://github.com/bensu/asterion/blob/master/project.clj#L29 using figwheel on the frontend part

bensu09:10:03

the only challenge was that to change my backend code (under app/app.js) I had to restart Electron on each change....

thheller13:10:42

@bensu why is your backend code not cljs? simple_smile

bensu14:10:44

@thheller: because I used a template that had a bunch of setup in js and didn't bother to extract the 3 functions I needed there into a cljs namespace. Also, some JS API's are very awkward to use from cljs (think d3) and it might be simpler to stay there to call them.

thheller14:10:08

@bensu just teasing ... but I agree some (most) "standard" js is quite awkward to use

reefersleep17:10:14

Hey peeps. I'm trying to get the result of <!'ing a chan inside a go block out of the go block - and failing. Can anyone tell me how? simple_smile

reefersleep18:10:06

I create a channel in my namespace using (def input-buffer (chan 1)), then, :onclick for a button, I do #(let [input-char (-> (sel1 ".char-input") .-value)] (go (>! input-buffer input-char))) , and then, inside a function body, I do (assoc cells cell-pointer (int (go <! (go (<! input-chan))))) But I can't get it to work - the return value from reading the chan is ignored it seems.

reefersleep18:10:31

I've tried with just the one "go <!" as well, at first, but that didn't work either

reefersleep18:10:00

The chan is passed in as a parameter called "input-chan" simple_smile

thheller18:10:15

you cannot do that

thheller18:10:51

go creates a block of code that runs async

thheller18:10:10

so you'll need to move the assoc into the go

thheller18:10:40

the return value from go is a channel that will eventually receive the return value of the go block

reefersleep18:10:49

@thheller: I'm trying to comprehend that. So how can I return something from a function if I want to wrap some part of the function body in a go block?

reefersleep18:10:13

Do I have to mutate a namespace-wide ref - like an atom or something - to affect the world outside of the go block?

thheller18:10:20

well you can create a local atom and mutate that

thheller18:10:01

consider go equals to a callback in js

thheller18:10:13

you do not call this callback, it will be called for you

thheller18:10:35

or a Promise

reefersleep18:10:56

I will hammock a bit on that comparison simple_smile Thank you a lot for taking the time to explain. I will attempt with the atom-mutating approach simple_smile

thheller18:10:32

well the callback comparison isn't entirely correct

thheller18:10:58

but it helped me in the beginning simple_smile

thheller18:10:43

FWIW the reason this doesn't work is that it would require blocking to wait for the click

thheller18:10:03

since the UI would be block, there would be no click ... simple deadlock

reefersleep19:10:26

@thheller: So, I could do this?

reefersleep19:10:34

(let [return-value (atom {})] (do (go (reset! return-value (<! input-chan)))) (assoc cells cell-pointer (int @return-value)))

thheller19:10:28

go returns immediately, which means the assoc happens without go having had a chance to run

thheller19:10:47

thus @return-value returning {}

thheller19:10:13

all code after that assoc also happens before the go executes

thheller19:10:54

async is a lot of fun isn't it? simple_smile

jaen19:10:25

@reefersleep: protip - you can enclose code in three backticks so it formats nicer, like so: \

some code

jaen19:10:39

(just without the slash)

jaen19:10:05

If you're doing it on one line then a single backtick is enough. So you can do something like this for example. Tripel backtics are useful for longer swathes of code.

thheller19:10:10

@jaen are you still working the es6 conversion stuff? I sort of gave up for a bit after looking at too much weird React js trying to identify the issue 😛

jaen19:10:15

No problem. It's easier to read that way after all.

jaen19:10:15

@thheller: didn't have time recently to do anything useful really, though I imagine figuring out what's breaking with advanced compilation might turn out to be a nightmare.

reefersleep19:10:21

Well @thheller, how would I return something from the go block, then? Pass in an atom and deref it elsewhere?

reefersleep19:10:32

(rather than immediately after)

thheller19:10:54

well you can only get to that from another go simple_smile

jaen19:10:15

Yeah, go blocks can't really return, just like callbacks.

thheller19:10:51

(go 1) returns (async/chan) and if you read from (<! c) you get 1 simple_smile

jaen19:10:11

Oh, does it?

jaen19:10:15

TIL then

reefersleep19:10:56

But if I do (go (<! c)), I get another chan, not 1, correct?

thheller19:10:02

in cljs you can only take/`<! from a channel inside go`

thheller19:10:21

teh fuck slack

thheller19:10:59

test /`<!` test

jaen19:10:10

Hm, you can't call take outside of a go block? I thought it was the counterpart of put.

jaen19:10:20

In that it can be called outside

thheller19:10:26

ok ... doesn't like the / 😉

thheller19:10:39

@jaen yeah but you really really shouldn't

thheller19:10:08

well I can't think of a reason why you would

thheller19:10:38

CLJ is a bit easier since it allows blocking, but there is no blocking in js

reefersleep19:10:06

Ok, let me ask this in a different way. If I mutate an atom passed in from outside a go block, then I could read it at some later point and view the result of the mutation, yeah?

thheller19:10:48

if LATER is some point after the actual mutation happened yes

jaen19:10:18

Yeah, with it being async and all

jaen19:10:46

All the usual concurrency gotchas might apply

reefersleep19:10:53

hehe yeah, later as in later time-wise

reefersleep19:10:17

not lexically

reefersleep19:10:22

If you can put it that way.

thheller19:10:55

probably better than the callback analogy is go equal to window.setTimeout (which it is under the hood)

thheller19:10:58

maybe that helps

jaen19:10:47

Which is still basically a scheduled callback, but yeah, maybe that's clearer on the fact it doesn't happen immediately.

reefersleep19:10:30

Maybe I should try asking about my problem rather than fumbling about with what I thought would help me with core.async

reefersleep19:10:42

I'm building a visual Brainfuck interpreter simple_smile As an exercise. I have a step function that takes a map representing the state of the interpreter, and returns the next state. I run this in a loop, swap/assoc'ing the state into an atom that represents my Reagent app state.

reefersleep19:10:01

This way, each state is shown in sequence in the app.

reefersleep19:10:18

But I have to block when I read a \,, because this means "read input from the user". Then the user has to type a character and click "input character" or whatever, and the interpreter would pick the input up and the loop would continue.

reefersleep19:10:44

So, I thought I could block using a chan, and maybe I can, I'm just a bit lost in the async of it now simple_smile

thheller19:10:31

yeah you want to stop the loop on \, then and call the go .. which then restarts the loop when the input arrives

reefersleep19:10:53

Ah that sucks, that complects the code.

thheller19:10:55

you can pass a function into the go that it can call with the new input

thheller19:10:14

so it doesn't know what happens

reefersleep19:10:06

So, basically pass the function with the looping body into the go?

thheller19:10:56

it is really hard to describe without knowing your code

thheller19:10:37

hehe you already have everything you need

reefersleep19:10:44

Since the loop is already wrapped in a go?

reefersleep19:10:18

(needed that for the timeout, needed the timeout in order to actually see the different sequential state

thheller19:10:51

pass current-symbol as an argument to the function

thheller19:10:01

and call retrieve in the go loop

thheller19:10:33

and check if \, there

thheller19:10:57

but that I really do not understand what is going on in that code, just a very rough idea

reefersleep19:10:38

It's a bit messy, planning on having it reviewed on a stack site once it's working

reefersleep19:10:54

let me just see if I follow you reads own code

thheller19:10:16

basically make step do one thing

reefersleep19:10:23

Inside my already existing go loop, I can just check for \, before running step, and if true, how do I block until input?

thheller19:10:10

you (<! (wait-for-that-click))

reefersleep19:10:27

just <! from the chan that I >! the typed char into?

thheller19:10:50

you already do the check if the loop should terminate

thheller20:10:15

you just need to check that outside step

reefersleep20:10:31

Oh yeah. That was more of a copy-paste thing, I think, I didn't properly get it when that entered the code base.

reefersleep20:10:57

I will attempt to implement this tomorrow, just about bedtime here.

reefersleep20:10:15

But one thing - when you said "basically make step do one thing", what did you mean?

reefersleep20:10:04

Decomplecting by removing the call to retrieve-current-symbol inside the step body?

reefersleep20:10:20

That makes sense simple_smile

reefersleep20:10:43

Well, thanks a lot for all of your helpe

reefersleep20:10:02

Hopefully, this is just the start of my asynchronous journey simple_smile

thheller20:10:32

you are almost there

colinkahn20:10:47

Not sure if this is the right way to go about this, but i'm trying to get a version of the clojurescript compiler used in this post: http://swannodette.github.io/2015/07/29/clojurescript-17/ but build to work in a webworker. I found the https://github.com/swannodette/cljs-bootstrap repo, but following the instructions i've hit a wall. When I run lein npm install in the cljs-bootstrap repo I get:

org.sonatype.aether.resolution.DependencyResolutionException: The following artifacts could not be resolved: org.clojure:clojure:jar:0.0-SNAPSHOT, org.clojure:clojurescript:jar:0.0-3653: Could not find
artifact org.clojure:clojure:jar:0.0-SNAPSHOT in clojars ()
I changed the version in project.clj to 0.0-SNAPSHOT after installing from the clojurescript repo using lein install (which wasn't in the steps, but just running ./scripts/build and changing it to the version it output wasn't working). Any advice would be appreciated simple_smile

thheller21:10:52

@colinkahn: not sure if any of this still works but probably just try to get the latest version of cljs and remove tools.reader

thheller21:10:41

[org.clojure/clojurescript "1.7.145"] is the latest

colinkahn21:10:22

@thheller: thanks, turns out it was a dumb mistake on my part, was updating the clojure version, not clojurescript

dnolen22:10:57

just cut Om 1.0.0-alpha8, fixes a subtle union bug found by @thomasdeutsch

dnolen22:10:05

back to my property based testing for UIs experiment ...