Clojurians
#cljs-dev
<
2017-01-05
>

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

angusiguess04:01:22

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.

angusiguess04:01:26

{: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}

mfikes04:01:44

@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

angusiguess05:01:41

Right on, @rohit I'd like to hear about it if you've got anything!

angusiguess05:01:57

If this ticket is a bit stale I could pick something else up too :slightly_smiling_face:

viebel16:01:33

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

viebel16: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

viebel16:01:17

The problem is that

(ns my.foo)
(def a 1)

viebel16:01:23

is transpiled into:

viebel16:01:34

goog.provide(‘my.foo');
goog.require('cljs.core');
cljs.user.a=1

viebel16:01:51

with the wrong namespace

mfikes16:01:40

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

mfikes16:01:45

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

viebel16:01:15

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

mfikes16:01:17

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

viebel16:01:36

This is exactly what I’m doing:

viebel16:01:17

Here is a minimal repo

viebel16:01:35

(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))

viebel16:01:49

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

viebel16:01:07

I ran it in planck and in klipse

viebel16:01:26

I will try in the JVM

mfikes16:01:25

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

mfikes16:01:17

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

viebel16:01:54

the namespace as a symbol or as a ns object?

viebel16:01:37

It worked with the ns as a symbol

viebel16:01:53

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

viebel16:01:07

provided that ‘cljs.core exists

viebel16:01:19

thx @mfikes

martinklepsch18:01:40

How do vectors, sets etc implement ISeq? Don’t see it anywhere in their definition

favila18:01:12

@martinklepsch They implement ISeqable, which returns another type which implements ISeq

martinklepsch18:01:13

@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

favila18:01:21

this is most likely thrown by vals

martinklepsch18:01:34

(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

favila18:01:29

i think you reversed comparator and keys in the constructor?

martinklepsch18:01:17

@favila there is no me.cljs file, saw it as well but don’t have an explanation for it… :smirk:

favila18:01:47

@martinklepsch nm

martinklepsch18:01:52

> 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})?

favila18:01:25

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

favila18:01:10

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

favila18:01:37

do you have console.log available? you could console.log the ValSeq object and see if its properties look right

martinklepsch18:01:20

Now I just need to figure out how to get the values of a map as a plain seq

martinklepsch18:01:29

:thinking_face:

martinklepsch18:01:10

(map second (seq data-map))
I guess that works for now

rauh18:01:38

@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.

martinklepsch18:01:38

@rauh I don’t want or need that, it was more of an implementation detail that leaked from using the underlying map

viebel18:01:04

I’m looking for the commit that allow cljs.* namespaces to be referenced by clj.* and vice-versa

favila19:01:29

@martinklepsch Your existing code should work fine and makes sense as long as (vals cc) is simply not allowed.

favila19:01:16

@martinklepsch the error you get is because (vals cc) is like (vals (vals data-map)), which doesn't really make sense

favila19:01:40

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

martinklepsch19:01:38

@favila hm, you’re right, not sure what I was doing different before but now it’s working fine even with vals

martinklepsch19:01:53

@favila thanks for your help! :slightly_smiling_face:

viebel19:01:36

Thx @anmonteiro

viebel19:01:47

@mfikes pointed me to the commit for self-host

viebel19:01:06

In the 2nd case of the cond, rewrite-ns-ast is not called!!!

anmonteiro20:01:28

@viebel: interesting, I'll need to look at it with in detail and maybe produce a failing test case

viebel20:01:43

I have one already

viebel20:01:52

I’m working on a patch...

viebel20:01:09

(require ‘clojure.spec)

viebel20:01:41

cannot be transpiled...

viebel20: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

viebel20:01:30

should I open a JIRA ticket?

anmonteiro20:01:22

Let me have a look

anmonteiro20:01:51

@viebel your example works for me

mfikes20:01:04

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

viebel20:01:05

you can transpile it?

viebel20:01:32

I mean: compile into js

anmonteiro20:01:43

trying analyze-str in a CLJS Node REPL

viebel20:01:59

I’m doing compile-str

viebel20:01:55

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

anmonteiro20:01:04

(require 'clojure.spec)

viebel20:01:27

There is a misunderstnading here:

viebel20: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)

viebel20:01:32

even if you pass a load function

anmonteiro20:01:45

yeah I'm trying that now

viebel20:01:56

because for resolving the ns, it calls analyze-deps

viebel20:01:07

while eval-str calls load-deps

viebel20:01:30

And the commit of @mfikes only modified load-deps

viebel20:01:25

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}}}

viebel20:01:10

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!

anmonteiro20:01:49

sounds like a bug to me

viebel20:01:56

so JIRA + patch?

viebel20:01:57

BTW, is there a way in planck or lumo to do transpilation?

anmonteiro20:01:51

I don't understand what you're asking now

anmonteiro20:01:13

at least in Lumo you have access to all the cljs.js functionality, so you can go meta all the way

viebel20:01:03

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

viebel20:01:17

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