Fork me on GitHub
#clojurescript
<
2016-03-05
>
venantius01:03:30

Is there a standard way to get the name of the type of something?

venantius01:03:08

not just the type but the name

dmitrig0101:03:27

like, (str (type x))?

nullptr01:03:29

(goog/typeOf something) if i understand correctly

nullptr01:03:55

(goog/typeOf 22.1) => ‘number'

nullptr01:03:05

(goog/typeOf “foo”) => ‘string'

venantius01:03:56

you are my hero

venantius01:03:11

what’s the proper require form for that?

nullptr01:03:25

none required, it’s just there :)

venantius01:03:04

that won’t really handle records

venantius01:03:16

cljs.user=> (goog/typeOf (atom 5))
“object”

venantius01:03:39

I’m wondering if there’s a way to take (type (atom 5)) and turn it into a string

nullptr01:03:12

(.getName (type (atom 5))) ?

venantius01:03:45

that throws an exception on the node runtime

nullptr01:03:23

it was a guess, pretty sure that’d work in jvm though

mfikes03:03:31

@venantius: if you know it is a record, (pr-str (type (atom 5))) yields "cljs.core/Atom".

seanirby04:03:11

can someone help me configure my dev server so that it picks up changes I make on the backend. I'm using figwheel and including the ring handler in figwheels 'ring-handler' option. I'm wrapping the handler using wrap-reload and its still not working. ..

nidu12:03:15

Does anyone have experience of exchanging Transit in SignalR?

george.w.singer14:03:26

How can one take a string like "file.extension" and return ".extension"? I.E.: How does one get the extension of a filename in cljs?

rauh14:03:07

@george.w.singer: goog.string.path.extension

mmeix14:03:24

ah, of course

rauh14:03:19

First thing is to github-search the google closure repo when I need some function.

venantius18:03:08

@mfikes once again you are a lifesaver

mfikes18:03:17

@venantius: if you want to detect if something is a record, you can see if it satisfies or implements IRecord but if it is a deftype perhaps you have to resort to seeing if you can call getBasis and seeing if it returns a vector. (Maybe there's a clever way…)

venantius18:03:59

I mean, I think it might also be okay to do something akin to:

venantius18:03:07

(let [t (type x)]
  (or (.-name t) (pr-str t)))

venantius18:03:50

just need to check that .-name isn’t the empty string instead of the pure boolean check

venantius18:03:56

but something like that would fit my needs

mmeix18:03:45

I just found, that in Planck I can do things like (+ 3/2 5/4) ... I was under the impression, that fractional numbers are/were not supported under Clojurescript - is this a misunderstanding on my side?

mmeix18:03:13

when I try this in regular Clojurescript, I get "java.lang.IllegalArgumentException : No method in multimethod 'emit-constant' for dispatch value: class clojure.lang.Ratio" , as I would expect

mmeix18:03:20

seems to be a misconception on my side ...

mmeix18:03:30

in a standard (lein) REPL (+ 3/2 5/4) yields 11/4

mmeix18:03:06

in Planck it's 2.75

solicode18:03:17

Yeah, there is no ratio support in ClojureScript. In Planck you’re just get plain JS number back.

mmeix18:03:29

of course

solicode18:03:44

But you’re right, this is behaving differently in plain ClojureScript and Boostrapped ClojureScript

solicode18:03:59

Surprised me too

mmeix18:03:29

would be great, if one could use fractional input in clojurescript

mmeix18:03:47

wouldn't mind decimal output

mmeix18:03:22

so we have to ask Mike, what the secret library is doing so simple_smile

solicode18:03:21

I don’t know if it’s Planck though. For example, you get the same result in something like http://clojurescript.io

solicode18:03:29

It seems to be a bootstrapped clojurescript thing

solicode18:03:34

not Planck specific

mmeix18:03:55

don't understand though

solicode19:03:36

I don’t know the details either. I’m sure he knows more about the reason for the difference.

mmeix19:03:49

it's a nive difference!

mfikes19:03:15

@mmeix @solicode that's odd. I thought the reader in ClojureScript converted ratios to doubles. AFK, so I trust you…

mmeix19:03:29

aha! so the reader in bootstrapped clojurescript understands ratios?

mmeix19:03:21

because it would be great, if we could input ratios in cls

mmeix19:03:46

(bear with a semi-beginner): could I use a boostrapped clojurescript in a web app?

mfikes19:03:21

@solicode: yes, that's why :)

solicode19:03:58

But plain ClojureScript doesn’t use this reader?

mmeix19:03:10

obviously not

mmeix19:03:01

ah- thanks!

mmeix19:03:20

ctford writes beautiful code, I found

mmeix19:03:39

very "naturally speaking"

mfikes19:03:42

@solicode: right. Different JVM-based reader for JVM ClojureScript

mmeix19:03:11

so I'll study ctford's example

solicode19:03:53

@mfikes: Ah, right. Thanks. Makes sense

mfikes19:03:33

So, even in regular ClojureScript, without ratio support, (/ 2) is 0.5. I suppose the only difference is this odd one with the reader. The JVM compiler could perhaps be updated to emit double literals for clojure.lang.Ratio. Wonder if pros/cons have been debated.

mmeix19:03:37

I once asked David Nolen on irc, if ratios would be supported sometime, but he said this wouldn't make much sense, JS not having sensible support - but this reader solution would be n intermediate solution, a quite nice one

mfikes19:03:13

Yeah, the implementation is probably only a handful of lines to add the defmethod

mmeix19:03:33

but it would be much slower to support the full Ratio methods, I understood

mmeix19:03:52

would like to have them though

mmeix19:03:03

for my music programming

mmeix19:03:00

Ratios are a quite important concept in music

mmeix20:03:14

@mfikes BTW the new version of Planck is pure joy!

mfikes22:03:28

@solicode: @mmeix: Interestingly, adding support for literals like 3/4 is truly one line. But, it is not possible to properly deal with 0/0, and the two infinities (forms like 1/0 and -1/0) because the ratio is formed in Clojure.

mmeix22:03:29

ah, I see

mmeix22:03:18

@mfikes but one could safeguard against division by zero, no?

mmeix22:03:21

rejecting a composite value as this as illegal

mmeix22:03:31

(but maybe I'm naive)

mfikes22:03:42

@mmeix: It boils down to a decision by humans, not a technical problem. ClojureScript uses both tools.reader variants. The question would be whether it was deemed worth it to have the Clojure version of tools.reader conditionally support ClojureScript (really, JavaScript) semantics when used as a reader for ClojureScript code.

mfikes22:03:43

@mmeix: Another way to look at is to consider (/ 0) in both Clojure and ClojureScript.

mmeix22:03:08

yes. I think this new reader form would enhance interchangability between cl and cls.

mmeix22:03:34

Bit I guess there are more things to consider as I can imagine in this case

mmeix22:03:07

thanks for thoughts and insights!

mfikes22:03:43

Yeah, if someone is interested in pursuing it, it would amount to hopping in #C07UQ678E and/or writing patches and garnering support / agreement that it is worth it. (And probably doing the same for tools.reader.)

mmeix22:03:29

I'm too much a beginner to medium user to try this, though ...

mfikes22:03:38

The easy part is easy simple_smile Duplicate this BigInt line for Ratio. But the NaN and Infinity and -Infinity are the hard bits. https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/compiler.cljc#L223-L224

mfikes22:03:56

The hard part, IMHO, is the fact that it touches on what the language should do, and whether consensus is possible to achieve.

mmeix22:03:00

maybe I'll try tomorrow, as an exercise, with a fresh mind ... exercise always a good thing

ctford22:03:56

Has anyone tried bootstrapped Clojurescript on PhantomJS? I'm trying to run some unit test, and getting a PhantomJS crash when I try js-eval.

mmeix22:03:46

@ctford wanted to say, how beautiful I find your code

mmeix22:03:19

workes on a web audio cljs myself, then found your's

mmeix22:03:35

run-with is ingenious!

mmeix22:03:28

ok, good night (it's late here in Austria)

mfikes22:03:47

@ctford: Try :static-fns true

ctford22:03:23

G'night @mmeix. Thanks for checking it out. simple_smile

ctford22:03:49

@mfikes: That's an interesting bug. :static-fns true doesn't seem to affect it, so probably not the same thing.

mfikes22:03:12

@ctford: Cool. There are two places you could set :static-fns true: 1) When you are building everything with JVM ClojureScript, and 2) When you are compiling a form with bootstrap ClojureScript. Either one might be needed.

mfikes22:03:22

@ctford: FWIW, I found that, to run cljs.test in Planck, this was needed. My guess is that the is macros and other machinery expand into enough nested JavaScript to provoke it.

ctford22:03:58

@mfikes: Wait, you're right! I'd only added the flag to the boostrapped compiler options. Adding it to the JVM compiler options too allows the test to run.

ctford22:03:24

@mfikes: Your theory about it being related to is helps me understand why I hadn't encountered it for production code.

ctford22:03:32

@mfikes: Excellent catch. simple_smile

mfikes22:03:08

@ctford: Hah, I’ve only travelled half a step farther down the same road you’re on. simple_smile

ctford22:03:44

@mfikes: So long as you step in every pothole first, sounds great to me. 😉

mfikes22:03:01

I hit the same stuff a week or so ago.