Fork me on GitHub

I'm interested in working on 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 🙂

Yehonathan Sharvit16:01:33

I’m having namespace issues with self-host transpilation of cljs code into js code

Yehonathan Sharvit16:01:50

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

Yehonathan Sharvit16:01:17

The problem is that

(def a 1)

Yehonathan Sharvit16:01:23

is transpiled into:

Yehonathan Sharvit16:01:34


Yehonathan Sharvit16:01:51

with the wrong namespace


@viebel Do you have all of those forms in a larger do?


When you eval, the new namespace is returned to you. You then thread that into your next eval.

Yehonathan Sharvit16:01:15

Yeah I know. I’m doing it...


In short, (ns will cause :ns to be returned as the symbol, then when you eval again, pass that as :ns

Yehonathan Sharvit16:01:36

This is exactly what I’m doing:

Yehonathan Sharvit16:01:17

Here is a minimal repo

Yehonathan Sharvit16:01:35

(require '[cljs.js :as cljsjs])
(def st (cljsjs/empty-state))
(binding [cljs.analyzer/*cljs-ns* ‘
               *ns* (create-ns ']
  (cljsjs/compile-str st "(def a 1)" identity))

Yehonathan Sharvit16:01:49

It returns: {:value "cljs.user.a = (1);\n”}

Yehonathan Sharvit16:01:07

I ran it in planck and in klipse

Yehonathan Sharvit16:01:26

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


Or, perhaps try binding ana/*cljs-ns*

Yehonathan Sharvit16:01:54

the namespace as a symbol or as a ns object?

Yehonathan Sharvit16:01:37

It worked with the ns as a symbol

Yehonathan Sharvit16:01:53

(cljsjs/compile-str st "(def a 1)" "bar" {:ns  'cljs.core} identity)

Yehonathan Sharvit16:01:07

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 ( :id {:id 1} {:id 2})))
Uncaught TypeError: me.cljs$core$IMapEntry$_val$arity$1 is not a function


this is most likely thrown by vals


(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


i think you reversed comparator and keys in the constructor?


@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: ( :id {:id 1} {:id 2})?


@martinklepsch no I thought your custom-comparator-set might have been calling new CustomComparatorSet with things in wrong order


My hunch is the ValSeq is holding on to something whose elements don't implement val


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




(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

Yehonathan Sharvit18:01:04

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


(vals (map val data-map)) isn't any better


@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! 🙂

Yehonathan Sharvit19:01:47

@mfikes pointed me to the commit for self-host

Yehonathan Sharvit19:01:06

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

Yehonathan Sharvit20:01:43

I have one already

Yehonathan Sharvit20:01:52

I’m working on a patch...

Yehonathan Sharvit20:01:09

(require ‘clojure.spec)

Yehonathan Sharvit20:01:41

cannot be transpiled...

Yehonathan Sharvit20:01:03

I’m looking more deeply in the code and I see that the code was patched for load-deps but not for analyze-deps

Yehonathan Sharvit20:01:30

should I open a JIRA ticket?


Let me have a look


@viebel your example works for me


Ahh, interesting… perhaps it fails if you just call analyze-str?

Yehonathan Sharvit20:01:05

you can transpile it?

Yehonathan Sharvit20:01:32

I mean: compile into js


trying analyze-str in a CLJS Node REPL

Yehonathan Sharvit20:01:59

I’m doing compile-str

Yehonathan Sharvit20:01:55

@anmonteiro can u send the code that you ran in lumo?


(require 'clojure.spec)

Yehonathan Sharvit20:01:27

There is a misunderstnading here:

Yehonathan Sharvit20:01:21

The code that fails is:

(require '[cljs.js :as cljsjs])
 (def st (cljsjs/empty-state))
(cljsjs/compile-str st "(require 'clojure.spec)" identity)

Yehonathan Sharvit20:01:32

even if you pass a load function


yeah I'm trying that now

Yehonathan Sharvit20:01:56

because for resolving the ns, it calls analyze-deps

Yehonathan Sharvit20:01:07

while eval-str calls load-deps

Yehonathan Sharvit20:01:30

And the commit of @mfikes only modified load-deps

Yehonathan Sharvit20:01:25

You can see the difference in lumo:>   (cljsjs/eval-str st "(require '" identity)
{:error #error {:message "No such namespace:, could not locate cljs/foo.cljs, cljs/foo.cljc, or Closure namespace \"\"", :data {:tag :cljs/analysis-error}}}>   (cljsjs/compile-str st "(require '" identity)
{:error #error {:message "No such namespace:, could not locate clojure/foo.cljs, clojure/foo.cljc, or Closure namespace \"\"", :data {:tag :cljs/analysis-error}}}

Yehonathan Sharvit20:01:10

In the case of eval-str, we have - while with compile-str, we have => was not tried at all!


sounds like a bug to me

Yehonathan Sharvit20:01:57

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

Yehonathan Sharvit20:01:03

I mean a regular way to write (foo 1) in the REPL and to get: foo(1)

Yehonathan Sharvit20:01:17

I think I found it: with -v flag, it shows it