This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-03-02
Channels
- # beginners (7)
- # calva (10)
- # cider (9)
- # cljdoc (2)
- # cljsrn (10)
- # clojure (35)
- # clojure-europe (1)
- # clojure-greece (1)
- # clojure-spec (31)
- # clojure-uk (6)
- # clojurescript (3)
- # community-development (2)
- # cursive (37)
- # duct (5)
- # emacs (7)
- # fulcro (40)
- # hoplon (7)
- # off-topic (8)
- # parinfer (1)
- # quil (6)
- # re-frame (7)
- # reagent (7)
- # shadow-cljs (45)
- # sql (17)
- # tools-deps (12)
- # yada (3)
@didibus As far as I'm aware, it was just the one guy, called out in the thread I linked to...
Tried to see how #()
does it with the variadic args but can't find the source for that macro
So, got it to work with vars, but would like it to work with anonymous functions as well, if possible (feels like I need another way of reorganizing the forms in a different macro to solve this) Current implementation
(defmacro read-args [f]
`(first (:arglists (meta #'~f))))
(defn use-log-func [log] (log true))
(read-args use-log-func) ;; Works
(read-args (fn [] (println "None"))) ;; Fails
(read-args (fn [one] (println "One"))) ;; Fails
;; Failure:
;; clojure.lang.PersistentList cannot be cast to clojure.lang.Symbol
What the macro receives is not a function, but code. So you will need to parse the code yourself and identify the args within it.
You can try this:
(defmacro read-args [f]
(if (symbol? f)
`(:arglists (meta (var ~f)))
`(do (defn ~'_ ~@(rest f))
(:arglists (meta (var ~'_))))))
This:
(let [in (java.io.PushbackReader. (StringReader. "#<Namespace user>"))]
(try (read in) (catch Exception e nil))
[(read in) (read in)])
returns '[Namespace user>]
How do I get the reader to skip over this thing entirely?use case: I’m parsing REPL sessions that can be interleaved with valid clojure expressions and their output
Another issue. I’m generating code like this:
(defn example-104
"clojure.core/extend"
[]
(defprotocol Dateable
(to-ms [t]))
(extend java.lang.Number
Dateable
{:to-ms identity})
(extend java.util.Date
Dateable
{:to-ms (fn* [p1__19578#] (.getTime p1__19578#))})
(extend java.util.Calendar
Dateable
{:to-ms (fn* [p1__19579#] (to-ms (.getTime p1__19579#)))})
(in-ns (quote speculative.clojuredocs-parser)))
but it seems that defprotocol is not supported well in defns: the symbol to-ms
cannot be resolved.I’m just reading examples from clojuredocs and generating a function for each example
@borkdude in your example to-ms
cannot be resolved because you're referring to a symbol/var before the protocol is defined
The protocol is defined at runtime of that function. The symbol is resolved at compilation time of that function
I fixed it now by emitting the defprotocol before the start of the function (same for import, require, etc.)
Creepy? Does it remind you of something else with a similar name that is creepy, perhaps? If it reminds you of "The Cask of Amantillado", then agreed, but the only thing I can see common between those is that they contain an Italian name 🙂
what’s the origin of this name for this problem btw. I tried to look it up before, but couldn’t find it
@borkdude I get several hits via a Google search for the term: Gilardi scenario. Yes, it was named for Steve (Stephen? not sure of spelling) Gilardi, who was one of the first to describe it.