Fork me on GitHub
#clojurescript
<
2016-12-31
>
udhan03:12:14

can we use spec.gen in clojurescript?

martinklepsch03:12:15

Not sure if there’s a kindle version available but I think it might be written with a system that allows mobi export

mfikes05:12:23

@udhan In ClojureScript, the namespace you want is cljs.spec.impl.gen

mfikes05:12:27

The reason for the impl is that otherwise a cljs.spec.gen namespace would collide with the cljs.spec/gen var.

udhan05:12:15

Why same is not true for clojure?

udhan05:12:19

Is it because there are no true ns in JavaScript world?

mfikes05:12:34

@udhan It has to do with the way the code is transpiled to JavaScript. A concrete example in your case is

(= js/cljs.spec.gen cljs.spec/gen cljs.spec.gen)
evaluates to true and if you look at the generated JavaScript, you get
cljs.core._EQ_.call(null,cljs.spec.gen,cljs.spec.gen,cljs.spec.gen)
So, in short you can see how namespaces and vars are implemented in the JavaScript.

mfikes05:12:00

You will trigger a helpful compiler diagnostic if you accidentally go down that path yourself:

cljs.user=> (ns foo.bar)
nil
foo.bar=> (def baz 3)
#'foo.bar/baz
foo.bar=> (ns foo.bar.baz)
WARNING: Namespace foo.bar.baz clashes with var foo.bar/baz at line 1
nil

udhan06:12:01

@mfikes Aha! Thanks for detailed explanation

scknkkrer14:12:56

Guys I have ubuntu 14.04 with clean install. I just follow these instructions: https://gadfly361.github.io/gadfly-blog/2016-11-13-clean-install-of-ubuntu-to-re-natal.html When i enter the init command: re-natal init blabla; here is the output: ------

scknkkrer14:12:53

Creating blabla Grab a coffee! Downloading deps might take a while... Creating Leiningen project Updating Leiningen project Creating React Native skeleton. Command failed: node -e "require('react-native/local-cli/cli').init('.', 'blabla')" ------------- Sorry for interrupted message and my bad english. I need your help, I don't get the point.

pesterhazy14:12:13

maybe you need to install node?

pesterhazy14:12:17

try node --version

pesterhazy14:12:33

also, #cljsrn may be a better place to ask

scknkkrer14:12:28

node --version command is giving me "v4.7.0" answer. I follow the instructions with no errors.

scknkkrer14:12:24

Guys: following code is fix my problem: sudo npm i --save-dev invarian I am sorry for early asking.

mrg20:12:32

Is there a proper way of reading a string with multiple forms (so that (multiple-read-string "1 2 3") would give me [1 2 3] and not just 1) or is a (str \[ the-forms \] the way to go?

mrg20:12:46

Or am I thinking about this the wrong way?

gfredericks20:12:42

you can do something with streams and calling read multiple times I think; I always do (str "[\n" the-forms "\n]")

gfredericks20:12:53

just to be paranoid about ;;

mrg20:12:36

i wasn't sure about how to get a stream from a string in cljs

mrg20:12:52

good call on the \n

gfredericks20:12:39

if you want to figure it out I'd check what kind of thing read expects

mrg20:12:18

read, like read-string, just takes a StringPushbackReader

mrg20:12:52

The actual magic or parsing a multiple-form cljs file must happen somewhere else

mrg20:12:04

read is also just reading the first item of the stream

mrg20:12:06

Actually, you were right, and I got some help from @yogthos

mrg20:12:47

I can work with that 🙂

mrg20:12:55

Thanks for the help @gfredericks

bert21:12:19

In cljs 1.9.293, it looks like there's no generator defined for boolean? by default. at the repl, if I try (s/gen boolean?), I get "unable to construct gen for function cljs$core$boolean?" - is this intentional?

bert21:12:03

Looking at the docstring for s/gen, it looks like I can supply an overrides map that would include a simple generator of booleans as a workaround, but I haven't found the right way to supply it - e.g. (s/gen boolean? {:cljs.core/boolean? clojure.test.check.generators/boolean}) doesn't work.

bert21:12:46

I must be making some kind of mistake - it looks like boolean? does have a generator implemented. https://github.com/clojure/clojurescript/commit/2a7454837244cf7de3dfed1e48f46f86c33a1809

bert21:12:46

alright this works with the bare cljs quick start jar, I must be screwing up deps somewhere.

bert21:12:12

even weirder, the stack trace for (s/gen boolean?) has 1.9.293 all over it:

Prompt will show when Figwheel connects to your application
To quit, type: :cljs/quit
cljs.user=> (require '[clojure.spec :as s])
nil
cljs.user=> (require 'clojure.test.check.generators)
nil
cljs.user=> (s/gen boolean?)
#object[Error Error: Unable to construct gen at: [] for: function cljs$core$boolean_QMARK_(x){
return (x === true) || (x === false);
}]
   cljs$spec$gensub (jar:file:/Users/bert/.m2/repository/org/clojure/clojurescript/1.9.293/clojurescript-1.9.293.jar!/cljs/spec.cljs:236:5)
   cljs$core$IFn$_invoke$arity$2 (jar:file:/Users/bert/.m2/repository/org/clojure/clojurescript/1.9.293/clojurescript-1.9.293.jar!/cljs/spec.cljs:872:29)
   cljs$spec$gen (jar:file:/Users/bert/.m2/repository/org/clojure/clojurescript/1.9.293/clojurescript-1.9.293.jar!/cljs/spec.cljs:858:51)
   cljs$core$IFn$_invoke$arity$1 (jar:file:/Users/bert/.m2/repository/org/clojure/clojurescript/1.9.293/clojurescript-1.9.293.jar!/cljs/spec.cljs:868:26)
   cljs$spec$gen (jar:file:/Users/bert/.m2/repository/org/clojure/clojurescript/1.9.293/clojurescript-1.9.293.jar!/cljs/spec.cljs:854:51)
nil

emccue22:12:10

I have a series of questions about reagent best practices, but I am having trouble formulating my thoughts into a stack overflow question that wont have only subjective answers. If any of you kind soul finds the time, could I have what I am writing in this toy project --torn apart-- code reviewed? https://github.com/bowbahdoe/test-clj/blob/master/src/cljs/site/components/navbar.cljs Specifically, I am wondering about stuff like the signature for navbar; should I do it like I am with [title & descs] or should I do [props & children] and have the data contained in props. Is it okay for me to just give keys based on the index if the data doesn't change? Is it okay for me to make that assumption or am I just introducing bugs down the line? Is the mutual recursion introduced by how I structured the data acceptable, or is there a good way to avoid that performance hit in this case? trampoline? In what ways is my code bad and in what ways should I feel bad?