Fork me on GitHub
#clojurescript
<
2016-04-13
>
perrpell00:04:33

Probably been asked a lot but what cljs grid css systems are available for cljs?

kenny00:04:17

Where is the string format function. I am running 1.8.40, however, it doesn't seem to be in the clojure.string namespace.

xcthulhu00:04:50

@kenny: In clojure format is just a shallow wrapper around Java's String/format: https://github.com/clojure/clojure/blob/clojure-1.7.0/src/clj/clojure/core.clj#L5503

kenny00:04:15

@xcthulhu: I am talking about clojurescript.

xcthulhu00:04:24

I know. It's not present in ClojureScript because it'd be a rather elaborate port job since it's got lots of corner cases.

nberger00:04:12

@kenny: there's goog.string.format which is quite similar AFAIK

kenny00:04:02

Seems like it was added then removed: > Backing this one out, goog.string.format defies advanced optimization and it provides few of the capabilities of Clojure's format - which does a lot because of java.util.Formatter. Apologies for the churn, but this is a simple thing for people to stub in themselves for the little bit of functionality it actually delivers. > David Nolen

nberger01:04:13

Interesting. So that's why a wrapper was not added to cljs.core, but it's fine to use it as needed directly from gclosure

razum2um01:04:48

could someone here point to up-to-date example to to get even simple cljs-eval in browser to work? https://github.com/swannodette/cljs-bootstrap seems to to work because

VM3766:1 Uncaught TypeError: cljs.env.default_compiler_env.cljs$core$IFn$_invoke$arity$0 is not a function(…)
and indeed the name above is a MetaFn object * using cljs-1.8.40

mfikes02:04:11

@razum2um: If you set up a browser REPL per Quick Start you can then evaluate things like this

cljs.user=> (require 'cljs.js)
nil
(cljs.js/eval-str (cljs.js/empty-state) 
  "(+ 1 2)" nil {:eval cljs.js/js-eval :context :expr} identity)
{:ns cljs.user, :value 3}

razum2um02:04:52

@mfikes: this perfectly works in planck etc on server, but I’d want to fire this in browser. when I puts this code i a blank cljs ns, wrap in a func to accept string, and fire from chrome console a get error above

mfikes02:04:23

I just did the above in Chrome. Using a browser REPL into Chrome.

razum2um02:04:32

hm, sounds newbie, but did you use https://github.com/binaryage/dirac otherwise where “cljs.core=>” prompt in chrome console? or did you do it in an ns, and refreshed..?

mfikes02:04:41

If you want to try it from the Chrome console, you can, for example:

(defn eval [s] (:value (cljs.js/eval-str (cljs.js/empty-state) s nil {:eval cljs.js/js-eval :context :expr} identity)))

mfikes02:04:30

@razum2um: If you want a cljs.user=> prompt, it sounds like you want a full REPL in the browser. In that case Replumb is probably the best reusable lib for building such a thing.

mfikes02:04:19

@razum2um: If it wasn’t clear what I was doing above: I established a regular ClojureScript REPL into Chrome (using Quick Start), and then required cljs.js (essentially loading its JavaScript implementation into Chrome dynamically), and then poked at it from the REPL, and then added a convenience fn named eval using the REPL, and used eval from Chrome’s console.

razum2um02:04:27

hm, seems I have some version issues. on server I have cljs.util/*clojurescript-version* but when requiring from cljs I get ANALYSIS ERROR: No such namespace: cljs.utils, could not locate cljs/utils.cljs, cljs/utils.cljc, or Closure namespace "cljs.utils" in file ...

razum2um02:04:20

..it’s an old app, which used cljs-0*, but I upgraded recently and restarted, rebuild everything

mfikes02:04:07

Hmm. Not horosho

mfikes02:04:59

It is in cljs.core (so you can just use it without qualifying it):

cljs.user=> cljs.core/*clojurescript-version*
“1.8.41”

razum2um03:04:40

cljs.core._STAR_clojurescript_version_STAR_
“1.8.40”
hm, probably should dig into smaller example, thanks for answers!

currentoor05:04:11

Anybody have suggestions for what to use for doing visual regression testing in a cljs/react app?

mikethompson06:04:40

@currentoor: in a Reagent app, the renderers produce hiccup - a clojure data structure (vectors and maps mostly) which describes the required HTML. So, unit tests can be done by comparing the hiccup actually returned from a renderer with the hiccup expected. In effect, the unit test would be comparing one data structure with another. Which is kinda neat. Hmm. Looking at your question again, I fear I'm not on topic here - you talked about "Visual Regression" ... so you want to do screenshot diffs, right?

danielgrosse08:04:31

I have an external javascript which I want to use in clojure script. The class of it mounts with a function and calls an function when it was successful, given an object as argument. This object contains the logic to control the functions of the class. How can I assign this object to a clojurescript function to access it?

slipset08:04:43

I came across the need to do this in Clojurescript (int \a)

slipset08:04:29

in Clojure, this returns 97, whereas in Clojurescript, it returns 0

slipset08:04:01

I can sortof understand the rationale behind this, as javascript does not have characters, but I still find it kind of strange.

slipset08:04:55

expected behaviour would be something like (.charCodeAt \a) which returns 97

slipset08:04:46

("a" | (0));       // (int \a)
("a" | (0));       // (int "a")
"a".charCodeAt();  // (.charCodeAt "a")
"a".charCodeAt();  // (.charCodeAt \a)

slipset09:04:07

which make sense since

slipset09:04:15

(macroexpand '(int \a))
(js* "(~{} | ~{})" "a" 0)

slipset09:04:07

in clojurescript, whereas in Clojure it's

slipset09:04:12

(source int)
(defn int
  "Coerce to int"
  {
   :inline (fn  [x] `(. clojure.lang.RT (~(if *unchecked-math* 'uncheckedIntCast 'intCast) ~x)))
   :added "1.0"}
  [x] (. clojure.lang.RT (intCast x)))
nil

slipset12:04:42

It does make sense

slipset12:04:05

since the definition for int in clojurscript is a macro which does just about that.

currentoor17:04:33

@mikethompson: Yeah exactly, screenshot diffs that could catch any visual problem including CSS blunders.

sbondaryev19:04:31

is it possible to make "compile-str" generate custom a name-space for a function not just cljs.user?

sbondaryev19:04:24

(cljs/compile-str (cljs/empty-state) “(func 123)”) => core.user.func.call(null,(123));

sbondaryev19:04:43

i need: (cljs/compile-str (cljs/empty-state) “(func 123)”) => some.workspace.func.call(null,(123));

mfikes20:04:45

@sbondaryev: You’d extract the (cljs/empty-state) out to a top-level so you can keep passing it back in (it is an atom) and then you’d eval an ns special to create the namespace you want, and then you can evaluate def statements in that namespace by passing in the :ns option as @jr points out.

sbondaryev20:04:19

@mfikes Could you please explain the case with empty-state. When I use only :ns option i have output without a namespace .func.call(null, (123))

jr20:04:50

the namespace set as :ns needs to be analyzed to populate cljs.analyzer/namespaces

jr20:04:48

after analysis the compiler can emit that namespace

mfikes20:04:33

@sbondaryev: So, when you ask for the evaluation of (func 123), part of what goes on is resolution of that symbol to a var (and then to a function value). The resolution of func will depend on which namespace you are in at the time (because, for example, a namespace may have referred func). If you pass in an empty analysis state, I would expect func to be unresolvable, unless it happens to be something in the standard lib...

mfikes21:04:51

@sbondaryev: Here is a gist. You appear to be asking a question about the last line in that gist. I’m talking about the lines previous to it that lead up to you being able to issue that last line. Seeing the whole thing together as a working example here might help: https://gist.github.com/mfikes/2de7f559a1e9a5ae12c67dc506e92f3d

sbondaryev21:04:46

@mfikes: Yes, thanks it’s clear now

sbondaryev21:04:32

in my case i created function earlier in the name space with a REPL

sbondaryev21:04:36

is it possible to say a compiler just switch state to this name-space

sbondaryev21:04:02

i tried (cljs.js/eval-str st "(ns foo.core)" nil {:eval cljs.js/js-eval :context :expr} identity)

sbondaryev21:04:18

and it seems to create the new ns without any def

sbondaryev21:04:41

and (cljs.js/eval-str st “(in-ns foo.core)" nil {:eval cljs.js/js-eval :context :expr} identity) doesn’t work for my

mfikes21:04:27

@sbondaryev: in-ns is a REPL special. It doesn't exist in cljs.core, just like there is no require function.

mfikes21:04:32

The :ns opt to eval-str is analogous to the concept of in-ns.

sbondaryev21:04:48

Ok, it works now but i still have a notice: Use of undeclared Var foo.core/func

sbondaryev21:04:04

I think this is a second step of resolution Var->value

mfikes21:04:53

@sbondaryev: Gotta run, but look at my gist. It has a step where func is defined in foo.core

sbondaryev21:04:55

yes, I see. you use cljs.js/eval-str to populate the namespace

sbondaryev21:04:39

in my case I have a func definition in .cljs file - and i would like generate a js which will use this definition