Clojurians
#cljs-dev
<
2016-10-05
>

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

viebel12:10:49

@dnolen I watched your talk on “Parsing with derivatives” https://www.youtube.com/watch?v=FKiEsJiTMtI&amp;feature=youtu.be

viebel12:10:18

How much of the clojure.spec implementation is inspired by this (amazing) paper?

dnolen12:10:48

@viebel only the parsing bits really and it’s a bit different since clojure.spec isn’t a typical parsing problem

viebel12:10:45

Does clojure.spec use least fix point stuff - as in the paper?

dnolen12:10:44

don’t think so, but I haven’t looked closely

viebel12:10:02

Do we support recursive definition in clojure.spec?

dnolen12:10:26

yes, or it wouldn’t be useful for Clojure data structures :slightly_smiling_face:

viebel12:10:39

I mean: can we define a spec that references itself in the definition?

viebel12:10:12

YOu know like in Context-Free grammar?

viebel12:10:15

I am trying...

dnolen12:10:48

also better to ask this stuff in #clojure-spec

dnolen12:10:57

parsing with derivatives is an implementation detail

dnolen12:10:25

clojure.spec needs to be able to capture the power of context-free grammars in order to satisfy it’s goals

viebel12:10:32

I also wanted to share with you that after your talk, I implemented the regex matcher in clojure and it runs fine in the browser: http://blog.klipse.tech/clojure/2016/10/02/parsing-with-derivatives-regular.html

dnolen12:10:58

cool, thanks, will have to look at that later

viebel12:10:43

Let me know if I misunderstood some stuff: this material is really not trivial :grimacing:

anmonteiro17:10:34

the snippet below works in the script/noderepljs but doesn’t succeed if I put it in self-host-test

(require '[cljs.js :as cljs])

(def st (cljs/empty-state))

(cljs/eval-str st
  "(ns cljs.user (:require [foo.core :as foo :refer [bar]]))"
  nil
  {:eval cljs/js-eval
   :load (fn [_ cb] (cb {:lang :clj :source "(ns foo.core) (defn bar [] :bar)"}))}
  (fn [{:keys [error value]}] (nil? error)))

anmonteiro17:10:44

can anyone spot if I’m doing something wrong?

anmonteiro17:10:59

should I be binding any variables that are e.g. bound at the REPL but not in the test?

anmonteiro17:10:17

the problem is the :refer

anmonteiro17:10:21

it fails in cljs.analyzer/check-uses

richiardiandrea17:10:35

I am trying to spot the problem but I don't see it ....weird

anmonteiro17:10:12

the difference between the version that produces the error and the one that works is: - when it works, (keys (get <@U07E9BBBN> :cljs.analyzer/namespaces)) has foo.core

anmonteiro17:10:36

- when it doesn’t work, the compiler env doesn’t have that namespace

richiardiandrea17:10:52

I think in replumb I have to wrap the require

anmonteiro17:10:53

which leads me to believe the compiler env is not getting bound somewhere?

richiardiandrea17:10:38

@anmonteiro I am checking here, it's been a while since I touched that https://github.com/Lambda-X/replumb/blob/master/src/cljs/replumb/repl.cljs#L622

richiardiandrea17:10:24

(the code was from planck) it does not look like is doing anything fancy

anmonteiro18:10:47

yeah I can’t figure it out

richiardiandrea18:10:30

ok let me fire up a replumb repl

richiardiandrea18:10:18

@anmonteiro remember one day I was asking about compilation stages...I had to do something like this: https://github.com/Lambda-X/replumb/blob/master/test/cljs/replumb/ast_test.cljs#L11

richiardiandrea18:10:50

maybe it is something relevant to you too

richiardiandrea18:10:00

but still it does not explain why it works in node

anmonteiro18:10:32

it’s actually using Node too in the Self-host test

richiardiandrea18:10:57

so it works here, I see (cljs.user cljs.core foo.core) in namespaces

richiardiandrea18:10:14

(def st (cljs/empty-state))

(def foo-core-load-fn (fn [{:keys [macros]} cb]
                        (cb {:lang :clj :source "(ns foo.core) (defn bar [] :bar)"})))

(cljs/eval-str st
  "(ns cljs.user (:require [foo.core :as foo :refer [bar]]))"
  nil
  {:load foo-core-load-fn}
  (fn [{:keys [error value]}]
    (println (keys (get <@U07E9BBBN> :cljs.analyzer/namespaces)))
    (println (nil? error))))
Prints:
;; ======================================================================
;; Testing with Node:

(cljs.user cljs.core foo.core)
false
In doo's node testing environment

anmonteiro18:10:45

so it’s failing

anmonteiro18:10:02

oh nevermind, I see foo.core. what’s false?

richiardiandrea18:10:18

I see foo.core, false is (nil? error)

anmonteiro18:10:25

so there’s an error..

anmonteiro18:10:15

what’s the error you see?

richiardiandrea18:10:32

oh @anmonteiro sorry for the error, I did not set :eval because I wanted to test with replumb than changed my mind...

richiardiandrea18:10:18

so the print is now:

(def st (cljs/empty-state))

(def foo-core-load-fn (fn [_ cb]
                        (cb {:lang :clj :source "(ns foo.core) (defn bar [] :bar)"})))

(cljs/eval-str st
  "(ns cljs.user (:require [foo.core :as foo :refer [bar]]))"
  nil
  {:eval cljs/js-eval
   :load foo-core-load-fn}
  (fn [{:keys [error value]}]
    (println (keys (get <@U07E9BBBN> :cljs.analyzer/namespaces)))
    (println error)))
---
;; Testing with Node:

(cljs.user cljs.core foo.core)
nil


richiardiandrea18:10:36

so it looks like it's working

richiardiandrea18:10:37

using:

[org.clojure/clojure "1.9.0-alpha11"]
[org.clojure/clojurescript "1.9.229" :scope "test"]

anmonteiro18:10:47

yeah I’m using master

anmonteiro18:10:58

something could have broken, would be good to figure out what

anmonteiro18:10:44

@richiardiandrea hrm, I can only repro this when the namespace has already been loaded

anmonteiro18:10:07

when cljs.js/*loaded* contains the NS

richiardiandrea18:10:10

because it skips the load

richiardiandrea18:10:55

in my tests here I always make sure I reset *loaded* before the next one

anmonteiro18:10:15

the root cause of my problem is because I already have the NS loaded

anmonteiro18:10:24

I just want to :refer a few vars

anmonteiro18:10:44

I wonder what Planck does with regards to this

anmonteiro18:10:56

do you know?

richiardiandrea18:10:16

not sure, I am checking in replumb

richiardiandrea18:10:07

so @anmonteiro the thing is you want to do two (ns cljs.user (:require ...)) where the second one refers more symbols than the first one?

anmonteiro18:10:21

not really, but I suppose they’re equivalent

anmonteiro18:10:53

equivalent because the NS is already loaded, and I want to require it and refer more symbols

anmonteiro18:10:20

@richiardiandrea oh.

anmonteiro18:10:26

I know what the problem is

anmonteiro18:10:41

I didn’t load the analysis cache :slightly_smiling_face:

anmonteiro18:10:54

so the NS is loaded, but the compiler doesn’t know about it :smile:

richiardiandrea18:10:06

yeah I always forget that part

anmonteiro18:10:11

thanks for taking your time to help!

richiardiandrea18:10:40

well you did it yourself ah ah :smile: