Fork me on GitHub
#clojurescript
<
2016-05-05
>
ajchemist00:05:25

I’ve just noticed there is defmacro in cljs. Is there a document how to use it properly?

sbmitchell00:05:47

@danielcompton I have wanted to potentially make use of defrecords but I dont know of a particular where it would shine over say using functions and maps of data. For what scenarios do you find defrecords a good fit?

paradoxquine03:05:50

Is there a way to make closure compiler break up methods so none of them are over 64k compiled? I'm trying to target rhino and currently only :optimizations :advanced will work, but the rebuild time on that prevents a good development experience

paradoxquine03:05:46

alternately, if i could precompile the entire clojurescript library with :optimizations :advanced in advance and then have the rest of my code use :whitespace that would work. i don't need the dead code elimination features at all

cigitia03:05:38

In ClojureScript, is it possible to use the #my.thing[1 2 3] or #my.record{:a 1, :b 2} reader forms that are documented in http://clojure.org/reference/datatypes? I’m having difficulty using them.

jonoflayham05:05:22

I’m having trouble understanding the relationship between lein-figwheel and Figwheel Sidecar - can anyone explain?

ajchemist06:05:13

@jonoflayham: lein-figwheel is lein plugin, and figwheel-sidecar(and also figwheel) is figwheel system.

xfcjscn09:05:36

I have some questions, need community's help.

xfcjscn09:05:38

I passed an atom: (defonce tasklist-atom (atom {:entries []})) to om/root function: (om/root tasklist tasklist-atom {:target tasklistel}) Now I can retrieve the atom content inside component constructor like this: (seq (:entries @tasklist-atom)) or (seq (:entries tasklist-atom)) . It should be an issue that I can retrieve the atom content via: (seq (:entries tasklist-atom)) right? Component Constructor Code Example: (defn render-tasklist [state owner {:keys [counter] :as local}] (println (seq (:entries state))) ;; print ({:subject "a", :id 2, :completed false}) (println (seq (:entries @state))) ;; print ({:subject "a", :id 2, :completed false})

xfcjscn09:05:20

Thanks in advance simple_smile

anmonteiro09:05:55

@xfcjscn: from Om's docs: "During the render phase, you treat a cursor as a value, as a regular map or vector. " https://github.com/omcljs/om/wiki/Cursors

xfcjscn09:05:11

@anmonteiro: Thanks a lot. I didn't go through the doc carefully.

urbanslug10:05:47

Hey, where can I read about cljsc files?

urbanslug10:05:54

Thanks turbopape

turbopape10:05:20

you’re welcome

urbanslug11:05:21

Hey, how would I go about catching errors involving XmlHttpRequest ? can’t transfer this knowledge to cljs http://stackoverflow.com/questions/26756752/how-to-catch-errors-involving-xmlhttprequest

octahedrion12:05:46

sorry I asked this before, but how does one cljs.js/eval forms that refer to functions in other namespaces ?

fasiha13:05:07

@urbanslug: the second answer there by Francois Dermu is how I'd go about it: I'm not 100% sure about this, but I wouldn't expect, e.g., goog.net.XhrIo to throw exceptions, but rather just return a status code, which your cljs code responds to. Are you actually seeing exceptions being thrown by XmlHttpRequest or anything else in JS?

bwstearns17:05:28

Has anyone tried making chrome extensions with cljs yet?

bwstearns17:05:36

(I'm sure someone has but I'm mildly surprised I haven't bumped into any discussion of it)

darwin17:05:23

Dirac would be a real-world example: https://github.com/binaryage/dirac

bwstearns17:05:24

@darwin Wicked cool. Thanks. I had seen the devtools repo but I must have misunderstood something and took it as not a chrome extension.

bwstearns17:05:42

the chromex-sample is just what I was looking for though

darwin17:05:07

(not= 'cljs-devtools 'dirac)

darwin17:05:37

dirac is a DevTools fork wrapped in a Chrome Extension

bwstearns17:05:53

I'm still on my first coffee of the day.

darwin17:05:57

cljs-devtools is just a library with some hooks into DevTools console (it does not need Dirac)

darwin17:05:26

definitely look into https://github.com/binaryage/chromex, cannot imagine starting a new chrome extension project without it

bwstearns17:05:39

awesome. I have historically avoided a lot of JS stuff just because I am not a fan of the language, but since finding cljs I have been looking around at a lot of areas that I had previously not dove too deep into, and the other day at work I found myself wishing for a chrome extension.

darwin17:05:11

you should be familiar with core.async, chrome apis are mostly async, you will be writing code spiced with a lot of go blocks, I guess (an example https://github.com/binaryage/dirac/blob/master/src/background/dirac/background/tools.cljs)

victorbjelkholm18:05:21

Hello guys and gals, I’m a bit confused why this is returning true

victorbjelkholm18:05:22

(number? (js/parseInt (last "123x")))

victorbjelkholm18:05:47

js/parseInt returns NaN which is Not a Number, but clojurescript says it is….

victorbjelkholm18:05:08

All I want to do really is to see if the last character in a string is a number, maybe there is an easier way

blissdev18:05:21

I think JS treats NaN as a Number type

bwstearns18:05:39

(number? (js/parseInt (last "sdfgsdfg")))

fasiha18:05:41

NaN is always a value representable by floating-point

victorbjelkholm18:05:14

so how could I figure out if the last character is a number or not?

spinningtopsofdoom18:05:15

I think (js/isNaN n) is what you need

fasiha18:05:18

Since the only numeric available in JS is double-precision floating point, NaN (as a valid double-precision floating-point) will make number? true

victorbjelkholm18:05:21

ah, ok… I’ll try that

spinningtopsofdoom18:05:32

to see if a number is a NaN

victorbjelkholm18:05:34

parseInt would return an Integer or NaN so sounds reasonable

bwstearns18:05:37

cljs.user=> (number? NaN)
true

victorbjelkholm18:05:50

@fasiha: I’ll try everything I can to not do regex 😉

blissdev18:05:27

isNan isn’t supported in IE from what I see

blissdev18:05:34

might have to polyfill

blissdev18:05:53

oh nvm, that’s just Number.isNan

victorbjelkholm18:05:58

blissdev: didn’t know, not a requirement from me though

bwstearns18:05:25

planck seems to think NaN is a number when tested with number?

fasiha18:05:59

I'd prefer (re-matches "[0-9]" (last "123x")). Makes it obvious what you're doing instead of complexting language specifics. Parsing to number and checking for NaN is much less obvious. Plus it'll work in Clojure when you want to share code.

sbmitchell18:05:48

base don the standard it should be a number

sbmitchell18:05:50

4.3.24 NaN number value that is an IEEE 754-2008 “Not-a-Number” value

victorbjelkholm18:05:06

fasiha: maybe, if you’re coming from clojure and are gonna write serverside and want to share. In this case is just the frontend and coming from a javascript background

mfikes18:05:16

@bwstearns: Right, and also (== NaN NaN) is false simple_smile

bwstearns18:05:45

No matter how much sanity cljs brings to the fight, js will always bring more insanity.

fasiha18:05:46

I think JS engines implement isNaN by checking if x==x because NaN is the only thing (so far) for which x!=x

fasiha18:05:31

@bwstearns: again, it's a floating point, IEEE 754 thing. All languages that use floating point will have those semantics.

mfikes18:05:09

@bwstearns: But NaN is a number, even though its name would lead you to believe otherwise. Clojure is the same: (number? Double/NaN) yields true

bwstearns18:05:42

@fasiha @mfikes But JS seems to be the only language that I run into NaNs frequently.

mfikes18:05:12

I think this all strictly following IEEE 754

mfikes18:05:28

Don’t get me wrong, JS is a funky language, but IEEE 754 is what this is all about simple_smile

sbmitchell18:05:28

Thats why we there are standards 😛 to make the counter intuitive "clear"

fasiha18:05:42

Yup: in Clojure (= Double/NaN Double/NaN) ; => false too simple_smile welcome to the world of floating-point! FYI, John Gustafson has described a unum alternative to floating-point which will solve most of these problems: http://ubiquity.acm.org/article.cfm?id=2913029 I believe there's a Java port too (and we'll hopefully get hardware support in a few years)

fasiha18:05:11

What @bwstearns says makes sense tho: I feel that I do run into NaN in cljs more than Clojure. Is that just because of parseInt?

bwstearns18:05:17

I think it's just more javascript-y to actually return NaN as a result so they end up getting passed around and pop up several layers later where numbers (real numbers, that you can do math with, you know what I mean) were expected. btw I didn't mean to wholly sidetrack the discussion from the initial topic but it does seem like a regex might be the easiest?

sbmitchell18:05:30

do you need interop or not?

sbmitchell18:05:42

rather clj + cljs solution I mean

bwstearns18:05:48

(!= nil (re-matches #"[0-9]" (last "123abc")))

sbmitchell18:05:50

seems fine I suppose. I try to avoid regex in most instances but to each his own

fasiha18:05:04

some? is more idiomatic than (!= nil …) I think? @bwstearns

bwstearns18:05:16

yeah i was just looking for a way to get rid of that lol

bwstearns18:05:25

boolean maybe?

bwstearns18:05:34

(boolean (re-matches #"[0-9]" (last "asdf5")))

sbmitchell18:05:04

re-find returns a boolean?

fasiha18:05:07

some? is what you want.

sbmitchell18:05:44

nvm no it doesnt

bwstearns18:05:59

seems like that'd be a helpful re-function

bwstearns18:05:08

maybe re-present

bwstearns18:05:22

or re-exists

fasiha18:05:53

re-findis a thing.

sbmitchell18:05:40

yea but I thought it returned a boolean 😕 heh still have to do something like (nil? (re-find ..))

bwstearns18:05:37

(contains? "0123456789" (last "asdf4")) No regex 😛

sbmitchell18:05:17

I would probably just stick with the regex 😛

bwstearns19:05:47

true. although other than feeling silly about typing [0-9] (a substantial barrier for recommending using the literal) I'm not sure how bad occasional literals are like that. If you were to change your mind about which characters should return true for this whole contains, you'd still need to modify the regex.

jr19:05:10

@victorbjelkholm: checkout goog.string/isNumeric

victorbjelkholm19:05:23

@jr: ah, that’s even more helpful, thanks a lot

jr19:05:15

(it appears to be implemented via regex btw)

juhoteperi19:05:21

@bhauman: Tested my Reagent project with the latest Devcards commit and it works, probably the problem was fixed by: https://github.com/bhauman/devcards/pull/100

bhauman19:05:48

@juhoteperi: cool, I'll get a release out pronto