This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-02
Channels
- # announcements (9)
- # babashka (67)
- # beginners (62)
- # bitcoin (2)
- # clara (1)
- # clj-kondo (62)
- # cljfx (6)
- # cljs-dev (25)
- # clojars (17)
- # clojure (142)
- # clojure-australia (2)
- # clojure-europe (42)
- # clojure-gamedev (2)
- # clojure-nl (31)
- # clojure-poland (10)
- # clojure-spec (14)
- # clojure-uk (30)
- # clojurescript (3)
- # conjure (1)
- # cursive (10)
- # data-science (1)
- # datascript (4)
- # datomic (9)
- # depstar (7)
- # fulcro (17)
- # girouette (15)
- # graalvm (44)
- # honeysql (20)
- # jackdaw (3)
- # jobs (8)
- # jobs-discuss (10)
- # juxt (5)
- # lein-figwheel (1)
- # lsp (175)
- # malli (19)
- # pedestal (2)
- # reagent (31)
- # reitit (2)
- # remote-jobs (3)
- # reveal (12)
- # sci (77)
- # shadow-cljs (22)
- # specter (6)
- # startup-in-a-month (2)
- # tools-deps (1)
- # xtdb (21)
@borkdude there’s no way to also read and get information about comments ;
in edamame, is there?
@borkdude literate programming in which the comments get parsed as markdown as explanatory between the code
@mkvlr I guess we could do something here:
https://github.com/borkdude/edamame/blob/9823a7af0edab2cf8596e345b6ea50979f1e9149/src/edamame/impl/parser.cljc#L538
but the question is:
what would you return when parsing (defn foo [] ;; nice comment \n 1)
if you stick to a strict format, e.g. ;;
only at the start of a line, you can probably parse this manually
this would have to be an opt-in thing anyway, right? Maybe the caller could decide what to turn this into? but not sure
thinking of wanting to get (comment ";nice comment")
or (line-comment ";nice comment")
back maybe
@mkvlr I can see it being useful to return comments when you are on the top-level but within balanced { .. }
for example, I can see this going wrong, like {:a 1 ;; foo \n :b 2}
=> incorrect map
I started in lread/rewrite-cljc-playground and am migrating that work into clj-commons/rewrite-clj v1 branch which will be merged to clj-commons/rewrite-clj main.
@borkdude ah right, guess top level only would be fine for my use case but unsure if it’s worth it then…
@mkvlr if top-level, I think this is pretty easy to parse manually, with (str/starts-with? (str/trim ...) ";")
@borkdude I am using sci in datalevin command line tool, it works for most part, however, there are some datalog queries that work in JVM do not work in sci
No implementation of method: :-find-vars of protocol: #’datalevin.parser/IFindVars found for class: datalevin.parser.Constant
You can point me to your repo and I can have a look if you can make some kind of failing test
this is what i currently doing, i expect it won’t work as I am not using sci namespaces, but I also tried using SciNamespace and SciVar, still doesn’t work
i saw that your datascript feature is using SciNamspace and copy-var, so I tried to do that, but still no luck
I need a complete example / test so I can have a look. If you can provide me with details instructions how to clone and run that, I'll take a look tomorrow
#?(:clj (defmacro deftrecord “Augment all datalevin.parser/ records with default implementation of ITraversable” [tagname fields & rest] (let [f (gensym “f”) pred (gensym “pred”) acc (gensym “acc”)] `(defrecord ~tagname ~fields ITraversable (~’-postwalk [this# ~f] (let [new# (new ~tagname ~@(map #(list ‘datalevin.parser/postwalk % f) fields))] (if-let [meta# (meta this#)] (with-meta new# meta#) new#))) (~’-collect [_# ~pred ~acc] ;; [x y z] -> (collect pred z (collect pred y (collect pred x acc))) ~(reduce #(list ‘datalevin.parser/collect pred %2 %1) acc fields)) (~’-collect-vars [_# ~acc] ;; [x y z] -> (collect-vars-acc (collect-vars-acc (collect-vars-acc acc x) y) z) ~(reduce #(list ‘datalevin.parser/collect-vars-acc %1 %2) acc fields)) Traversable (~’-traversable? [_#] true) ~@rest))))
`#?(:clj (defmacro deftrecord "Augment all datalevin.parser/ records with default implementation of ITraversable" [tagname fields & rest] (let [f (gensym "f") pred (gensym "pred") acc (gensym "acc")] `(defrecord ~tagname ~fields ITraversable (~'-postwalk [this# ~f] (let [new# (new ~tagname ~@(map #(list 'datalevin.parser/postwalk % f) fields))] (if-let [meta# (meta this#)] (with-meta new# meta#) new#))) (~'-collect [_# ~pred ~acc] ;; [x y z] -> (collect pred z (collect pred y (collect pred x acc))) ~(reduce #(list 'datalevin.parser/collect pred %2 %1) acc fields)) (~'-collect-vars [_# ~acc] ;; [x y z] -> (collect-vars-acc (collect-vars-acc (collect-vars-acc acc x) y) z) ~(reduce #(list 'datalevin.parser/collect-vars-acc %1 %2) acc fields))` Traversable (~’-traversable? [_#] true) ~@rest))))
I see yes. So:
(deftrecord Aggregate [fn args]
IFindVars (-find-vars [_] (-find-vars (last args))))
expands in some defrecord
call which needs the IFindVars
protocol to be around. This is where it gets a little hacky, but you can make this work. In sci, due to GraalVM limitations, protocols are implemented as multimethods.
E.g. this is how Datafiable
is added to the sci config of babashka:
https://github.com/babashka/babashka/blob/bbf144fbce66c6986253119eb81392a440cb17c6/src/babashka/impl/protocols.clj#L33$ bb -e "(require '[clojure.core.protocols :as p] '[clojure.datafy :as d]) (defrecord Foo [] p/Datafiable (datafy [_] :foo)) (d/datafy (->Foo))"
:foo
It magically works, but it works around the byte code restriction by using multimethods. This is a little bit undocumented right now and the implementation might change in the future
yeah, it seems a little odd. a parser should just take some data in and produce some other data probably
are you aware of https://github.com/lambdaforge/datalog-parser?