This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-07-31
Channels
- # admin-announcements (23)
- # announcements (3)
- # beginners (59)
- # boot (122)
- # clojure (117)
- # clojure-berlin (3)
- # clojure-dev (3)
- # clojure-italy (3)
- # clojure-japan (10)
- # clojure-russia (69)
- # clojurebridge (12)
- # clojurescript (183)
- # clojutre (14)
- # code-reviews (4)
- # core-async (79)
- # core-logic (18)
- # core-matrix (1)
- # cursive (7)
- # datascript (1)
- # datomic (18)
- # editors (3)
- # events (18)
- # hoplon (20)
- # ldnclj (24)
- # luminus (1)
- # off-topic (1)
- # other-lisps (1)
- # re-frame (12)
- # reagent (104)
@dnolen: minimal example - https://github.com/mhuebert/def-in-ns
@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
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
@mfikes you can try the last example with foo.z, which definitely exists (because it’s required in that file), with the same result
@mfikes I’m trying to use :ns
to pass in names of namespaces that I already have created and am using elsewhere
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.
@mfikes I had been looking at that ticket (CLJS-1363) before, which is what led me to think I could do this somehow
@mfikes is expected behaviour that if you pass in an existing namespace to :ns that def x 1
would set x in that namespace?
@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
@mfikes yes I believe that works; there’s just no way to set a var on it after creating it.
@mfikes yeah . 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.
@mfikes I just realized I had a last minute change, it used to be called ‘other’ and loaded from ‘core'
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.
@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
@mhuebert: You are passing an (cljs/empty-state)
to cljs/eval
. Thus cljs/eval
can’t know about foo.core
, right?
@mikes I haven't figured out yet what else I can pass in there, or how to require
inside eval
Should note that I can see from the examples how to use :require in ns from node, but unsure of load-fn for browser
would this be a recommended way to create a zero-dependency ClojureScript example, using master, targeting the browser? https://gist.github.com/mhuebert/1b2dd588e34d1ada7fb1
@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.
@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)
@mhuebert: One consequence of the approach is that the evaluation JavaScript engine can be different than the compiler JavaScript engine.
@mfikes interesting. so this might happen on iOS for example? (in a browser I imagine they’d be the same?)
@mhuebert: Exactly. With JavaScriptCore you can achieve multithreading by setting up multiple engines.
@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?
@mhuebert: With ClojureScript REPLs, there is the :analyze-path
REPL option. Perhaps there is nothing like that for bootstrapped ClojureScript.
@mhuebert: Lots of questions arise surrounding that if you don’t have the source available.
@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
@mhuebert: There is cljs.js/require
which would do that (and of course also load the related JavaScript).
@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.
@mfikes ahh I had seen require in there but didn’t click where it fits into the picture
@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?
@mfikes looks like eval function is passed {:source "goog.provide(\"foo.zzz\")”}
and the returning callback is passed nothing
@mhuebert: I’m referring to this one: https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/js.cljs#L516
@mhuebert: You should get a map containing :error
or :value
keys according to the docstring, if I’m reading it correctly
@mfikes yeah. and I remember programming around that api earlier. suddenly I’m confused!
@mhuebert: The question I had asked earlier about :ns
perhaps applies only to eval-str
and :simple
@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}
@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.
@mhuebert: Right. If you are in :none
mode that seems to differ. I’m wondering if there is a bug.
@mfikes does that work by calling (ns 'new-ns), & then adding ’new-ns the :ns option for future evaluations?
@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.
@mfikes I had no :output-dir set, that was my problem . Looks like the same output with :none
@mfikes correct. might it be a cache option somewhere - “these functions are already compiled"
@fluke777, @meow: running a cljs app in Electron is really easy. live reloading and repl etc working smoothly
any hints why figwheel would be throwing ClassNotFound (on Java code I use server-side) on startup ??
btw, lein repl, I believe, won’t boot up your app, so repl and figwheel are not comparable
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.
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.
plus it's a template, not a framework, which makes it kind of a moving target anyway.
yeah, I use it from time to time when I can’t get some configuration in my project.clj right.
@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.
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.
Recompiling doesn’t seem to fix it, at times. Odds are pretty high I’m just doing something weird.
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.
want to be able to attach a repl to the server so I can recompile without needing to restart lein
hmm, yeah, I have zero experience with luminus other than reading the generated project.clj
hmmm, and what does myproj.analysis.clj have? Looks like it is trying to use org.myproj.Service, but that doesn’t exist
yeah, sorry can’t help much there. I don’t have any experience with luminus. I think the author hangs out here. @yogthos
@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
and Planck 1.0! http://planck.fikesfarm.com
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)
how far we've come https://twitter.com/horse_js/status/622488071548702721
Congrats, @dnolen!!
@arohner: straight D3 isn't bad
@ericnormand: thanks, as I said above, lots people worked on getting this thing moving
@stuartsierra: yeah, that’s what I’m leaning towards