Fork me on GitHub
#clojurescript
<
2015-09-01
>
sonnyto11:09:35

noob question... why doesn't (-> 1 (fn [x] x)) work ? but (-> 1 foo) does work where (def foo (fn [x] x)

plexus11:09:26

It's because -> is a macro, it would turn it into (fn 1 [x] x)

sonnyto11:09:49

yeah thanks...

nikp11:09:52

You could do (-> 1 ((fn [x] x))) though it's a bit ugly

sonnyto11:09:53

couldn't the macro be written so that it doesnt require wrapping a lambda in a () ?

sonnyto11:09:16

this is non-intuitive

nikp11:09:56

You could probably write your own macro to do that.. though yes, it is kind of strange that lambda's aren't accounted for in thread-first/last macros

tcrayford11:09:22

@sonnyto: go look at the definition of -> and all will make sense. Them special casing things would probably be bad imo

sonnyto11:09:04

yeah thanks. it makes sense why it behaves this way but non-intuitive

joelkuiper13:09:31

I’m getting a : No single method: _setup of interface: cljs.repl.IJavaScriptEnv found for function: -setup of protocol: IJavaScriptEnv, compiling:(cemerick/piggieback.clj:149:5) when trying to use boot

joelkuiper13:09:40

is there a common solution to this?

martinklepsch13:09:24

@joelkuiper: make sure you use recent versions of clojurescript and boot-cljs-repl

joelkuiper13:09:19

@martinklepsch: [org.clojure/clojurescript "1.7.122" :scope "provided”] [adzerk/boot-cljs "1.7.48-3" :scope "test”] [adzerk/boot-cljs-repl "0.1.10-SNAPSHOT" :scope "test”]

joelkuiper13:09:26

these seem to be the most recent

martinklepsch13:09:35

@joelkuiper: then I think another dependency is pulling in the wrong version of piggieback, try boot show -d

pandeiro13:09:51

how should one refer to goog.DEBUG in code? something like (when js/goog.DEBUG ...) ?

martinklepsch13:09:43

@pandeiro: I’m not sure but maybe you could even omit the js/?

pandeiro13:09:04

i would have to (:require ...) something then right?

pandeiro13:09:19

or maybe not

martinklepsch13:09:55

goog is loaded by default. I think this is similar to using things with fully qualified namespaces after they’ve been required somewhere else.

joelkuiper13:09:15

@martinklepsch: ah yes “bouncer” was the issue … which came with Luminus, thanks simple_smile

pandeiro13:09:18

@martinklepsch: yeah makes sense, good call... and it works

martinklepsch13:09:23

(not sure if this is to be considered “clean” but I think it would work)

martinklepsch13:09:15

@joelkuiper: thinking about it you should have gotten a warning about that — would you mind checking?

rauh13:09:41

Does (when goog.DEBUG .. get elided nowadays or do we still need to apply a type hint?

joelkuiper13:09:04

sure, this is all the output I got I think …

<< started HTTP Kit on http://localhost:3000 >>

Starting file watcher (CTRL-C to quit)...

clojure.lang.Compiler$CompilerException: java.lang.IllegalArgumentException: No single method: _setup of interface: cljs.repl.IJavaScriptEnv found for function: -setup of protocol: IJavaScriptEnv, compiling:(cemerick/piggieback.clj:149:5)
     java.lang.IllegalArgumentException: No single method: _setup of interface: cljs.repl.IJavaScriptEnv found for function: -setup of protocol: IJavaScriptEnv

martinklepsch13:09:30

@rauh good q! will test simple_smile

mikethompson13:09:39

I've always used a type hint (when ^boolean goog.DEBUG ....

mikethompson13:09:50

It certainly used to be required

mikethompson13:09:15

Unless anything has happened in the last couple of months

pandeiro13:09:22

@mikethompson: a re-frame question: when a handler needs to dispatch to another, but that second handler needs the state set by the return value of the first - how does re-frame deal with that scenario?

martinklepsch13:09:27

@mikethompson: @rauh type hints are still required. Wondering if that could be fixed by adding it to the var when using goog-define (this way at least for custom defines it wouldn’t be necessary anymore)

mikethompson13:09:19

@pandeiro: the second handler won't be run until after the first finishes. So the 2nd handler will be able to access any state (assumidly in app-db) that it needs when it is (later) run.

pandeiro13:09:27

@mikethompson: dispatch uses a setTimeout or something to only execute on next tick?

mikethompson13:09:45

events dispatched are queued

joelkuiper14:09:21

stupid question, but I’m trying to get cljs to work with boot … but it keeps complaining about ClojureScript could not load :main, did you forget to specify :asset-path? this is the config I’m playing with now https://gist.github.com/joelkuiper/fe63fde980b7e786bfbd

martinklepsch14:09:49

@joelkuiper: let’s chat in #C053K90BR

onetom14:09:06

any reason for using (.. js/window -location -hash) instead of js/window.location.hash?

martinklepsch14:09:15

"js/something is for accessing a js object, but you shouldnt nest dots after that, since it is not clojure compatible syntax and it was going to be removed.” from http://stackoverflow.com/questions/24239144/js-console-log-in-clojurescript — that’s a year ago though 😄

martinklepsch14:09:18

I remember seeing this discussed before and often use things like js/console.log since then

dnolen14:09:19

@onetom: @martinklepsch: I don’t where people came to the conclusion it was going to removed

martinklepsch14:09:37

yeah me neither

dnolen14:09:38

it’s never going to be removed, it’s a convenience for JS interop

martinklepsch14:09:48

Maybe add a comment there @dnolen?

dnolen14:09:53

so you might as well use it if it’s less ugly

onetom14:09:33

dnolen: thanks. i like convenience simple_smile i will carry your words on this to my colleagues tomorrow.

onetom14:09:13

is there an equivalent of the arguments js variable in clojure?

f = function(){console.log(arguments)}
f(1, 2, 3)
prints [1, 2, 3] which is a #js[]

onetom14:09:19

i was using (fn [& args] (clj->js args)) but that's a bit of an overkill to transform it back and forth between persistent data structures...

dnolen15:09:43

@onetom: perhaps you can explain why you need access to arguments

dnolen15:09:02

@onetom: also if you need to convert a seq into an array use into-array not clj->js.

onetom15:09:10

i was just trying to translate google analytics snippet and wanted to keep it as close to the original implementation as possible, so it's easier to keep it up-to-date when it changes...

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
         (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
         m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
         })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

onetom15:09:03

where can i learn these things from, btw? where is it documented? i've learnt cljs primarily from your https://github.com/swannodette/lt-cljs-tutorial/blob/master/lt-cljs-tutorial.cljs

dnolen15:09:35

@onetom: accessing arguments just isn’t idiomatic ClojureScript, there’s really no reason to do that.

dnolen15:09:52

this isn’t performance critical code either, and even if it was you wouldn’t want to use arguments then either

dnolen15:09:58

just convert the seq into an array

bbss15:09:20

When testing using figwheel, is there a way to clear the tests currently defined, other than refreshing the connected browser?

bhauman17:09:38

@bbss: that seems to be the most effective, surefire way. And its simple as well. You could undef your root testing namespace (set! js/example_tests nil) and that will delete all your current tests. Never tried it though.

pandeiro18:09:54

are there any examples of using re-frame with datascript instead of a simple map as the db state?

not-much-io18:09:25

Can anyone help with this problem of params inside a POST disappearing? And less importantly a problem with response being a single semicolon. -> https://gist.github.com/not-much-io/764c5bb5b46c804b6a42

zoldar19:09:01

@not-much-io: are you running the the app with :dev set? if not, missing wrap-params may be a problem

not-much-io19:09:40

@zoldar I already got it working with help from the clojure chatroom. I was running :dev but the problem was that cljs-ajax default format was :edn. Setting it to json and wrapping using https://github.com/ring-clojure/ring-json#wrap-json-params worked for me simple_smile

meow20:09:37

weird - I just did lein new figwheel om-tut -- --om and the project doesn't have any om stuff in it

meow20:09:19

what's going on?

meow20:09:00

this is crazy

meow20:09:28

looks like a bug in Lein on Windows

meow20:09:19

I don't know much about lein but in looking at the source for the figwheel template it sure looks to me like the following should be aborting and spitting out an error, but it doesn't:

C:\Users\Patrick\code> lein new figwheel om-tut -- --foobar
Generating fresh 'lein new' figwheel project.

meow20:09:49

this is lein 2.5.2

shaun-mahood20:09:59

@meow: Weird, I just did the same command on a Windows machine and it brought om in and looks fine to me

meow20:09:59

C:\Users\Patrick\code> lein version
Leiningen 2.5.2 on Java 1.8.0_45 Java HotSpot(TM) Client VM

shaun-mahood20:09:11

@meow: Running Windows 10 64 bit on

Leiningen 2.5.1 on Java 1.8.0_31 Java HotSpot(TM) 64-Bit Server VM

meow20:09:41

and, why me? 😞

meow20:09:52

and, what now?

shaun-mahood20:09:58

I also get the error message

C:\Dev\om-tut>lein new figwheel om-tut -- --foobar
Unrecognized option: --foobar . Should be one of --om --reagent

meow20:09:19

I'll trade places with you 😉

shaun-mahood20:09:45

I get all the errors you don't, so I'm pretty sure it balances

meow20:09:58

fair enough

meow20:09:03

or unfair enough

shaun-mahood20:09:20

Yeah, Windows is nothing but equally unfair

meow20:09:55

I have to say I've had surprisingly few problems with clojure on windows

meow20:09:15

this one is weird

meow20:09:32

wonder if wiping out my m2 dir would do anything

meow20:09:04

@shaun-mahood: what version of lein are you on?

shaun-mahood20:09:08

I tried it about a year ago and it had a bunch of minor issues, but have run into only 1 or 2 since using it for real in the past 6 months. Usually it's related to file system stuff that was never really tested on Windows before I used it I think

shaun-mahood20:09:34

Looks like 2.5.1, and I have a bit older Java than you do too

meow20:09:44

I've just been working with it for about 4 months

meow20:09:56

I think they made some big changes in 2.5.2

shaun-mahood21:09:45

Ahh, that might be it then. I'll wait for you to get them fixed before upgrading simple_smile Or at least try it on a fresh VM before putting it on my normal work machine.

meow21:09:57

Yeah, they definitely touched lein new in 2.5.2 https://github.com/technomancy/leiningen/blob/master/NEWS.md

shaun-mahood21:09:15

I've gotten away from the habit of using lein templates other than figwheel and have never used the flags. I've found that building up my project.clj one thing at a time has given me a lot fewer long term problems. I ran into a lot of issues with chestnut initially that seemed pretty Windows specific.

meow21:09:59

@shaun-mahood: same here - I just happened to be checking out the Om tutorial and trying out the figwheel template

meow21:09:09

otherwise I never use templates

meow21:09:30

and I've been using boot

meow21:09:00

but lately I've gotten into bhauman's devcards and have been looking into figwheel more

shaun-mahood21:09:09

Oh cool - how are you liking devcards? Figwheel is one of my favourite things ever at this point and I'm really looking forward to getting some time to dive in to devcards too

meow21:09:33

devcards is awesome

meow21:09:24

I didn't really understand them until I just dove in and looked at the ones Bruce had created as examples and then it clicked

meow21:09:56

By dive in I mean I did a git clone and ran them on my machine and looked at the source for the example cards

meow21:09:27

Now I'm a big fan

shaun-mahood21:09:19

It's funny, I was experimenting with creating a way crappier version of devcards when Bruce released it, trying to solve similar problems but in a way uglier and more cumbersome way.

meow21:09:50

I need to be able to have one or more canvas elements in my devcards so I'm looking at how best to support that using react/om

meow21:09:59

And I want to add eval and repl options to devcards, but I'd be happier if someone else did it.

meow21:09:41

I've got too many other things I'd rather be doing. But I'll do it if I have to.

shaun-mahood21:09:50

Since I started using figwheel I haven't found the need for a repl very often. Out of curiosity, what are you trying to do in devcards that needs eval and a repl?

meow21:09:13

tutorials

shaun-mahood21:09:35

oh cool, that would be an awesome use for it

shaun-mahood21:09:24

Have you seen the tutorials that have been on the LispCast site recently?

shaun-mahood21:09:22

Oh they're pretty cool, check out the top 4 posts http://www.lispcast.com/

shaun-mahood21:09:35

Might give you some ideas for your own tutorials

meow21:09:36

Another unmentioned difference between cljs and clj: the class function doesn't exist in cljs

meow22:09:48

@shaun-mahood: I'm going to be working on adding turtle graphics support to cljs in devcards

meow22:09:04

hence the need for canvas and repl

meow22:09:38

I got a little sidetracked going down this rabbit hole: https://github.com/decomplect/ion/blob/master/src/ion/ergo/l_system.cljc

meow22:09:21

Gonna use Lindenmayer systems to generate the data to drive the turtle graphics

shaun-mahood22:09:32

Oh man that is a pretty big rabbit hole

shaun-mahood22:09:38

From "I need to draw some lines" to that is a pretty good jump

meow22:09:07

@shaun-mahood: I never had a chance to play with fractals so I figured now was a good time. simple_smile

meow22:09:19

And maybe fractal music as the l-system data could be sent to overtone as well.

shaun-mahood22:09:43

Yeah, I'm pretty sure that's gonna take up some of your time simple_smile

meow22:09:31

Well, the l-system library is pretty much done, other than adding more grammars and playing with the flexibility it has.

meow22:09:02

It's pretty crazy how much power can be packed into so little code.

shaun-mahood22:09:50

It'll be interesting to see how it can be used. Maybe some fractal music videos!

meow22:09:23

fractal battle bot music videos