Fork me on GitHub
#clojurescript
<
2015-07-31
>
mfikes01:07:28

@mhuebert: The :ns key for eval doesn’t create a namespace, it is just there to let you evaluate in an existing namespace (see http://dev.clojure.org/jira/browse/CLJS-1363) Does foo.core really exist here? https://github.com/mhuebert/def-in-ns/blob/master/src/foo/examples.cljs#L9

mfikes01:07:06

This line behaves like regular ClojureScript (which is different than Clojure): https://github.com/mhuebert/def-in-ns/blob/master/src/foo/examples.cljs#L18

mhuebert01:07:58

@mfikes you can try the last example with foo.z, which definitely exists (because it’s required in that file), with the same result

mhuebert01:07:20

@mfikes I’m trying to use :ns to pass in names of namespaces that I already have created and am using elsewhere

mfikes01:07:22

With respect to line 18, I believe the reason is that analysis of the (def x 1) form occurs statically in the namespace that the do form was evaluated in. In other words, analysis doesn’t occur at runtime.

mhuebert01:07:01

@mfikes I had been looking at that ticket (CLJS-1363) before, which is what led me to think I could do this somehow

mhuebert01:07:36

@mfikes is expected behaviour that if you pass in an existing namespace to :ns that def x 1 would set x in that namespace?

mhuebert01:07:38

@mfikes I see. the only reason I was trying to create a new namespace & then def in it is because I can’t seem to def in anything other than cljs.user

mfikes01:07:44

@mhuebert: Although, I’ve been exercising eval-str not eval so perhaps there’s a bug.

mhuebert01:07:20

@mfikes I see. I can try eval-str.

mfikes01:07:35

@mhuebert: After the do on line 20, foo.totally-new should exist.

mhuebert01:07:01

@mfikes yes I believe that works; there’s just no way to set a var on it after creating it.

mfikes01:07:32

@mhuebert: You could to it in another eval.

mfikes01:07:07

@mhuebert: In other words, you need to do two evals, one after the other.

mhuebert01:07:23

@mfikes yeah simple_smile. and that’s fine. I’m currently hopping back and forth from eval a lot for these reasons. but if I can get the :ns option to work that will cut down on a lot of it.

mfikes01:07:36

@mhuebert: What loads foo.examples?

mhuebert01:07:13

@mfikes I just realized I had a last minute change, it used to be called ‘other’ and loaded from ‘core'

mhuebert01:07:41

@mfikes just pushed a fix

mhuebert01:07:47

so ‘core loads ‘examples. z is just there because I wanted to verify that there was no difference between trying to call from core vs. from another namespace that’s required by examples. but it was all the same.

mhuebert01:07:24

@mfikes odd, with eval-str I get the same thing, ".x = 1”, from the first example. regardless of whether I pass ‘foo.z or ‘foo.core to :ns

mhuebert01:07:00

I’m running all these from the build from ./script/uberjar on master

mfikes02:07:00

@mhuebert: You are passing an (cljs/empty-state) to cljs/eval. Thus cljs/eval can’t know about foo.core, right?

mhuebert08:07:44

@mfikes good question.

mhuebert08:07:57

@mikes I haven't figured out yet what else I can pass in there, or how to require inside eval

mhuebert10:07:56

Should note that I can see from the examples how to use :require in ns from node, but unsure of load-fn for browser

mhuebert10:07:26

would this be a recommended way to create a zero-dependency ClojureScript example, using master, targeting the browser? https://gist.github.com/mhuebert/1b2dd588e34d1ada7fb1

mfikes11:07:52

@mhuebert: def a var initialized with (cljs/empty-state) and then pass that to the cljs.js API methods. The state is actually an atom so analysis side effects will be placed in there by the cljs.js API.

mhuebert12:07:53

@mfikes thanks, yes that works. now I can: === def into a new namespace** 1. eval ‘(ns foo.b) 2. (def bar 1) using same compiler state and :ns ‘foo.b 3. outside of eval I can now call (foo.b/bar) === call existing functions in non-cljs.user namespaces (also works for def) given existing namespace foo.q with function bar, 1. eval ‘(ns foo.q) - “create" a new ns (it already exists outside compiler-state) 2. eval ‘(declare bar) with` :ns ‘foo.q`, same compiler state (already exists outside) 3. eval ‘(bar) with same compiler state and :ns ‘foo.q - will call the existing function (defined elsewhere)

mfikes12:07:12

@mhuebert: One consequence of the approach is that the evaluation JavaScript engine can be different than the compiler JavaScript engine.

mhuebert12:07:10

@mfikes interesting. so this might happen on iOS for example? (in a browser I imagine they’d be the same?)

mfikes12:07:50

@mhuebert: Exactly. With JavaScriptCore you can achieve multithreading by setting up multiple engines.

mfikes12:07:22

@mhuebert: Out of curiosity, are you using :simple or :none?

mhuebert12:07:28

@mfikes it seems weird to (ns ..) and (declare ..) things that already exist; clearly the purpose is to prepare the compiler state. do you know if there would be a more direct way to achieve the same thing?

mhuebert12:07:06

(more of an ‘import’ or ‘require’ than ‘declare’ and ‘create’)

mfikes12:07:45

@mhuebert: With ClojureScript REPLs, there is the :analyze-path REPL option. Perhaps there is nothing like that for bootstrapped ClojureScript.

mfikes12:07:33

@mhuebert: Lots of questions arise surrounding that if you don’t have the source available.

mhuebert12:07:02

@mfikes right. this relates to requiring things generally. In the examples above I still can’t figure out how to get core.async things into the compiler state

mfikes12:07:56

@mhuebert: There is cljs.js/require which would do that (and of course also load the related JavaScript).

mfikes12:07:52

@mhuebert: Perhaps if you somehow know out-of-band that the source is already loaded, your *load-fn* can NOOP, and just call back as if it did.

mhuebert12:07:29

@mfikes ahh I had seen require in there but didn’t click where it fits into the picture

mfikes12:07:04

@mhuebert: When you call eval a map is passed to the callback which contains :ns. If you eval a form that changes the namespace, like (ns ‘foo.bar.baz), does the symbol for that namespace get passed in the callback?

mhuebert12:07:48

this is the callback for js-eval or the return value?

mhuebert12:07:29

@mfikes looks like eval function is passed {:source "goog.provide(\"foo.zzz\")”} and the returning callback is passed nothing

mhuebert12:07:00

@mfikes odd… instead of a map I’m seeing the last value from the evaluated forms

mfikes12:07:23

@mhuebert: Right. Was just looking at the source. I think the docstring has a bug.

mfikes12:07:11

@mhuebert: You should get a map containing :error or :value keys according to the docstring, if I’m reading it correctly

mhuebert12:07:45

@mfikes yeah. and I remember programming around that api earlier. suddenly I’m confused!

mfikes12:07:06

@mhuebert: Perhaps you are recalling eval-str’s behavior.

mhuebert12:07:24

@mfikes I was using eval-str before so that would make sense

mfikes12:07:18

@mhuebert: The question I had asked earlier about :ns perhaps applies only to eval-str and :simple

mhuebert12:07:36

@mfikes it doesn’t make much difference to me whether I use eval or eval-str. I thought eval would be faster since it doesn’t have to parse a string. when I use eval-str, I see: {:ns foo.zzz, :value 1}

mfikes12:07:24

@mhuebert: This is when you eval-str with ”(ns foo.bar.baz)”?

mhuebert12:07:37

(ns foo.zzz)

mfikes12:07:26

@mhuebert: When you call eval-str, you pass an :ns opt to evaluate the form in. I’m wondering if, in :simple mode you can then execute an ns form to change the namespace, and have it call back with the new :ns value.

mhuebert12:07:14

@mfikes it doesn’t seem possible to ‘change’ the namespace…

mhuebert12:07:30

@mfikes it remains in whatever namespace you put in :ns (or cljs.user)

mfikes12:07:54

@mhuebert: Right. If you are in :none mode that seems to differ. I’m wondering if there is a bug.

mhuebert12:07:57

@mfikes unless I can go into some kind of REPL mode

mhuebert12:07:17

i’ll try :none

mhuebert12:07:02

for the REPLs you’re working on - you have some kind of in-ns?

mfikes12:07:16

@mhuebert: Yes, both Replete and Planck have in-ns REPL specials

mhuebert12:07:28

@mfikes does that work by calling (ns 'new-ns), & then adding ’new-ns the :ns option for future evaluations?

mhuebert12:07:15

@mfikes compiling with :none either takes forever or hung, trying it again

mfikes12:07:46

@mhuebert: Replete and Planck implement in-ns by updating an atom with the new symbol. But they both have a bug where they don’t properly create the namespace if it doesn’t yet exist.

mhuebert13:07:48

@mfikes I had no :output-dir set, that was my problem simple_smile. Looks like the same output with :none

mfikes13:07:32

@mhuebert: Interesting. For me, under :none, eval-str returns the new namespace.

mhuebert13:07:29

@mfikes ah, cljs.js/require leads to the same path - load-fn in a browser

mhuebert13:07:05

@mfikes - but you were thinking of a no-op - let me try that

mfikes13:07:36

@mhuebert: Yes. But, that may not work given that there is no source to analyze.

mhuebert13:07:31

@mfikes correct. might it be a cache option somewhere - “these functions are already compiled"

martinklepsch16:07:51

@fluke777, @meow: running a cljs app in Electron is really easy. live reloading and repl etc working smoothly simple_smile

curtosis17:07:47

any hints why figwheel would be throwing ClassNotFound (on Java code I use server-side) on startup ??

curtosis17:07:15

lein repl starts fine.

roberto17:07:52

that is weird

curtosis17:07:14

cljsbuild throws a different error... can't find hiccup.form

roberto17:07:16

btw, lein repl, I believe, won’t boot up your app, so repl and figwheel are not comparable

curtosis17:07:23

which could be a hint

curtosis17:07:54

though no clue why it can't find hiccup.form 😕

roberto17:07:23

does it tell you where it is looking for it?

roberto17:07:35

like, what cljs file is throwing the error….

roberto17:07:56

sometime when I have cryptic stuff like that is due to my typos

curtosis17:07:26

yeah, it's failing on my (only) cljs file, line 1 - i.e. on the :require

curtosis17:07:56

[hiccup.form :refer [select-options]]

roberto17:07:34

hmmm, can you use hiccup with cljs?

roberto17:07:42

I didn’t know that

roberto17:07:56

I don’t think so

curtosis17:07:18

hmmmmm...... I hadn't even thought of that.

curtosis17:07:35

stupid one-language-on-two-platforms-first-world-problem

curtosis17:07:43

(assuming that's the issue...)

roberto17:07:09

yeah, I think that is the issue

roberto17:07:27

looking at the source code, there is no indication that it is a valid cljs package.

curtosis17:07:58

yeah... and in fact, the ootb luminus uses sablono, which is hiccup-like

curtosis17:07:15

(exists? sablono.core/select-options) => true simple_smile

curtosis17:07:46

though not sure why :requiring that isn't working.... sigh.

roberto17:07:25

what error are you getting this time?

curtosis17:07:55

couldn't find sablono.core. but it turns out thatt's because I am not a smart man. luminus loads selmer which is not sablono.

roberto17:07:35

yeah, the standard stumbling blocks when you are using an ootb framework….

curtosis17:07:26

I want to like it, and it's kind of nice to have a bunch of stuff that works together.... but you lose the knowledge of everything that's in and out.

curtosis17:07:59

plus it's a template, not a framework, which makes it kind of a moving target anyway.

roberto17:07:48

yeah, I use it from time to time when I can’t get some configuration in my project.clj right.

curtosis17:07:00

grrrr... okay, well cljsbuild works again, but now figwheel is crashing again

curtosis17:07:07

s/again/still

jeffmk17:07:23

@curtosis: I’m having the same struggles with Luminus. Worse, I’m new to ClojureScript (and pretty noobish with Clojure period). So about 6 things to learn at once. That with having to restart figwheel every now (thinking that it’s my fault when it’s not) and then when things aren’t working, lead to frustrating times.

roberto17:07:39

why do you have to restart figwheel?

jeffmk17:07:10

I don’t know. Things just get weird every now and then, and restarting seems to fix it. I’m not experienced enough to figure out what the actual problem is. Taking the Windows route.

curtosis17:07:17

well, because it's not running simple_smile

curtosis17:07:34

(in my case)

roberto17:07:35

I haven’t had the need to restart figwheel, tbh

jeffmk17:07:49

It may well be my fault.

roberto17:07:01

if I need it to recompile, I just add some whitespace, or something trivial

jeffmk17:07:54

Recompiling doesn’t seem to fix it, at times. Odds are pretty high I’m just doing something weird.

roberto17:07:03

hmmm, interesting

roberto17:07:57

also: lein clean lein figwheel when all else fails

jeffmk17:07:09

All in all I’ve been quite happy with things. I can tell things will be much smoother and productive once I get the hang of it.

roberto17:07:33

yeah, I’m still getting the hang of it.

jeffmk17:07:37

Seems revolutionary in fact.

roberto17:07:54

want to be able to attach a repl to the server so I can recompile without needing to restart lein

roberto17:07:01

and have a more interactive dev cycle

curtosis17:07:07

it's really baffling why it's even trying to load my java code.

roberto17:07:29

well, it will try to execute your clojure code so it starts up a server

roberto17:07:08

oh, but it is luminus

roberto17:07:27

hmm, yeah, I have zero experience with luminus other than reading the generated project.clj

curtosis17:07:13

the server runs fine

roberto17:07:24

ah, I see, just read the docs

curtosis17:07:25

(if I do cljsbuild separately)

curtosis17:07:36

and figwheel has been running fine previously

roberto17:07:02

what specific error are you getting? can you paste it?

dnolen17:07:06

ClojureScript now optionally self-hosts

tcrayford18:07:52

congrats David. Awesome work

roberto18:07:01

hmmm, and what does myproj.analysis.clj have? Looks like it is trying to use org.myproj.Service, but that doesn’t exist

curtosis18:07:24

yup, it imports it.

curtosis18:07:40

again, this works fine when I build and run the server

curtosis18:07:48

it's only figwheel that's barfing.

roberto18:07:13

hmmm, yeah, this seems to be related to luminus’ config

curtosis18:07:25

but it was working! lol

roberto18:07:11

welcome to the twilight zone

curtosis18:07:20

I dislike that.

roberto18:07:17

yeah, sorry can’t help much there. I don’t have any experience with luminus. I think the author hangs out here. @yogthos

curtosis18:07:30

I think it's a figwheel problem, but you may be right.

roberto18:07:55

did you try lein clean ?

curtosis18:07:20

in a brand-new shell, too

orther18:07:21

@dnolen: Not sure if you care but FYI in http://swannodette.github.io/2015/07/29/clojurescript-17/ you're link to Maria Geller's twitter account is her old one. Her new one is https://twitter.com/maria__geller

orther18:07:23

Also, awesome stuff in that article!

dnolen18:07:09

@orther: thanks fixed

mfikes18:07:50

Congrats to everyone! This is a big day. simple_smile

nullptr18:07:53

btw, cljs source highlighting seems to have made its way to dev channel (no longer need canary) — it’s in Version 45.0.2454.15 dev (64-bit)

andrewhr18:07:10

congratz to both @mfikes and @dnolen for today achievements simple_smile

ul19:07:50

bootstrapped cljs on node 3x times faster to start up than clj

ul19:07:20

it takes 0.8 s, which is acceptable for writing cli scripts

ul19:07:11

node alone takes 0.3 s

dnolen20:07:31

all the code from my last blog post

dnolen20:07:27

not much to it simple_smile

dnolen20:07:25

it’s official now

arohner20:07:22

I need graphing. Is there anything newer / better maintained that c2 or strokes?

Lambda/Sierra20:07:58

@arohner: straight D3 isn't bad

dnolen20:07:23

@ericnormand: thanks, as I said above, lots people worked on getting this thing moving simple_smile

arohner20:07:41

@stuartsierra: yeah, that’s what I’m leaning towards

mfikes21:07:08

@ul: If you have a Mac, I’d be interested in a comparison between Planck and bootstrapped ClojureScript on Node on your machine. time planck -e '(+ 1 2)'