This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-05
Channels
- # beginners (29)
- # boot (29)
- # cider (54)
- # cljs-dev (99)
- # cljsjs (31)
- # cljsrn (39)
- # clojars (32)
- # clojure (171)
- # clojure-austin (2)
- # clojure-berlin (5)
- # clojure-brasil (3)
- # clojure-greece (2)
- # clojure-italy (1)
- # clojure-korea (11)
- # clojure-spec (202)
- # clojure-uk (166)
- # clojurescript (130)
- # cursive (54)
- # datomic (99)
- # dirac (18)
- # figwheel (6)
- # hoplon (23)
- # lambdaisland (3)
- # leiningen (8)
- # luminus (14)
- # off-topic (11)
- # om (3)
- # om-next (24)
- # onyx (59)
- # planck (25)
- # protorepl (10)
- # re-frame (49)
- # reagent (14)
- # ring-swagger (2)
- # rum (46)
- # schema (1)
- # slack-help (6)
- # specter (7)
- # testing (7)
- # untangled (115)
- # yada (1)
I'm interested in working on http://dev.clojure.org/jira/browse/CLJS-981 if it's still relevant! Just a quick pass on edn output to start.
{:bindings [], :expr (str 1), :runs 1000000, :elapsed 19}
{:bindings [], :expr (str nil), :runs 1000000, :elapsed 13}
{:bindings [], :expr (str "1"), :runs 1000000, :elapsed 16}
{:bindings [], :expr (str "1" "2"), :runs 1000000, :elapsed 41}
{:bindings [], :expr (str "1" "2" "3"), :runs 1000000, :elapsed 52}
@angusiguess I recall that @rohit made some progress on the idea a while back but I don’t recall it being specifically related to CLJS-981
Right on, @rohit I'd like to hear about it if you've got anything!
If this ticket is a bit stale I could pick something else up too 🙂
I’m having namespace issues with self-host transpilation of cljs code into js code
The way I’m doing the transpilation - inside klipse - is by breaking the code into expressions. And transpile them one after the other. If the expression is a ns-form I’m evaluating the form before transpiling it
The problem is that
(ns my.foo)
(def a 1)
is transpiled into:
goog.provide(‘my.foo');
goog.require('cljs.core');
cljs.user.a=1
with the wrong namespace
@viebel See https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/js.cljs#L949
When you eval, the new namespace is returned to you. You then thread that into your next eval.
Yeah I know. I’m doing it...
In short, (ns my.foo)
will cause :ns
to be returned as the symbol my.foo
, then when you eval again, pass that as :ns
This is exactly what I’m doing:
https://github.com/viebel/klipse/blob/fix-compile/src/klipse/lang/clojure.cljs#L90-L102
Here is a minimal repo
(require '[cljs.js :as cljsjs])
(def st (cljsjs/empty-state))
(binding [cljs.analyzer/*cljs-ns* ‘my.foo
*ns* (create-ns 'my.foo)]
(cljsjs/compile-str st "(def a 1)" identity))
It returns: {:value "cljs.user.a = (1);\n”}
I ran it in planck and in klipse
I will try in the JVM
Well, I’d try putting :ns
in the opts instsead of binding it to see if that works. See https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/js.cljs#L940
the namespace as a symbol or as a ns object?
It worked with the ns as a symbol
(cljsjs/compile-str st "(def a 1)" "bar" {:ns 'cljs.core} identity)
provided that ‘cljs.core
exists
How do vectors, sets etc implement ISeq? Don’t see it anywhere in their definition
@martinklepsch They implement ISeqable, which returns another type which implements ISeq
@favila Hm. Ok. I’m implementing that but I get some very strange behavior when calling first
on my custom collection:
(-first (vals (org.martinklepsch.cc-set/set-by :id {:id 1} {:id 2})))
Uncaught TypeError: me.cljs$core$IMapEntry$_val$arity$1 is not a function
(println "map vals type" (type (vals {:a 1 :b 2})))
(println "map" (first (vals {:a 1 :b 2})))
(println "cc-set vals type" (type (vals cc)))
(println "cc-set" (first (vals cc)))
Both of these type printlns print cljs.core/ValSeq
— still the last line fails@favila there is no me.cljs
file, saw it as well but don’t have an explanation for it… 😏
> i think you reversed comparator and keys in the constructor?
What do you mean? Referring to this: (org.martinklepsch.cc-set/set-by :id {:id 1} {:id 2})
?
@martinklepsch no I thought your custom-comparator-set might have been calling new CustomComparatorSet
with things in wrong order
do you have console.log available? you could console.log the ValSeq object and see if its properties look right
Now I just need to figure out how to get the values of a map as a plain seq
:thinking_face:
(map second (seq data-map))
I guess that works for now@martinklepsch Silly question: Why do you want keys
and vals
work for you custom set? They don't work on cljs.core set's either.
@rauh I don’t want or need that, it was more of an implementation detail that leaked from using the underlying map
I’m looking for the commit that allow cljs.*
namespaces to be referenced by clj.*
and vice-versa
@martinklepsch Your existing code should work fine and makes sense as long as (vals cc)
is simply not allowed.
@martinklepsch the error you get is because (vals cc)
is like (vals (vals data-map))
, which doesn't really make sense
@favila hm, you’re right, not sure what I was doing different before but now it’s working fine even with vals
@favila thanks for your help! 🙂
@viebel: https://github.com/clojure/clojurescript/commit/23632baa35f86de8866dede624545bc0cdf4a2bb
@mfikes pointed me to the commit for self-host
https://github.com/clojure/clojurescript/commit/16af9f651f09e5c3f91098270ffacb806b907302 Is there a reason why it was not applied to self-host compilation? https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/js.cljs#L515-L522
In the 2nd case of the cond
, rewrite-ns-ast
is not called!!!
@viebel: interesting, I'll need to look at it with in detail and maybe produce a failing test case
I have one already
I’m working on a patch...
(require ‘clojure.spec)
cannot be transpiled...
I’m looking more deeply in the code and I see that the code was patched for load-deps
but not for analyze-deps
should I open a JIRA ticket?
Let me have a look
@viebel your example works for me
(in Lumo)
you can transpile it?
I mean: compile into js
trying analyze-str
in a CLJS Node REPL
I’m doing compile-str
@anmonteiro can u send the code that you ran in lumo?
(require 'clojure.spec)
There is a misunderstnading here:
The code that fails is:
(require '[cljs.js :as cljsjs])
(def st (cljsjs/empty-state))
(cljsjs/compile-str st "(require 'clojure.spec)" identity)
even if you pass a load function
yeah I'm trying that now
because for resolving the ns, it calls analyze-deps
while eval-str
calls load-deps
And the commit of @mfikes only modified load-deps
https://github.com/clojure/clojurescript/commit/16af9f651f09e5c3f91098270ffacb806b907302?w=1
You can see the difference in lumo:
my.foo=> (cljsjs/eval-str st "(require 'clojure.foo)" identity)
{:error #error {:message "No such namespace: cljs.foo, could not locate cljs/foo.cljs, cljs/foo.cljc, or Closure namespace \"cljs.foo\"", :data {:tag :cljs/analysis-error}}}
my.foo=> (cljsjs/compile-str st "(require 'clojure.foo)" identity)
{:error #error {:message "No such namespace: clojure.foo, could not locate clojure/foo.cljs, clojure/foo.cljc, or Closure namespace \"clojure.foo\"", :data {:tag :cljs/analysis-error}}}
In the case of eval-str
, we have cljs.foo
- while with compile-str
, we have clojure.foo
=> cljs.foo
was not tried at all!
makes sense
sounds like a bug to me
so JIRA + patch?
BTW, is there a way in planck or lumo to do transpilation?
I don't understand what you're asking now
at least in Lumo you have access to all the cljs.js
functionality, so you can go meta all the way
I mean a regular way to write (foo 1)
in the REPL and to get: foo(1)
I think I found it: with -v
flag, it shows it