joker

Discuss all things joker, the Clojure interpreter/linter on top of Go. https://github.com/candid82/joker
benedek 2018-05-21T13:10:28.000015Z

Hi, is anybody here?

benedek 2018-05-21T13:11:14.000201Z

I wonder how would i go about search a clj* file for a given keyword with joker

benedek 2018-05-21T13:11:21.000026Z

Any pointers?

Candid 2018-05-21T15:42:37.000474Z

not sure I understand the question. Can you elaborate?

benedek 2018-05-21T16:06:50.000215Z

I want to write a script where i would look for certain keywords in a relatively big project

benedek 2018-05-21T16:08:17.000590Z

I was thinking joker would be ideal for the task but cant really figure out how to "read" my clj/s/c source with joker

benedek 2018-05-21T16:08:41.000180Z

So i can walk the data to find keywords

benedek 2018-05-21T16:08:50.000731Z

Hope this makes sense

Candid 2018-05-21T16:31:56.000645Z

if you just need to find keywords, cannot you just use grep? Or do you need to understand semantics of the code (function names vs keywords vs let bindings etc)?

benedek 2018-05-21T17:52:22.000618Z

Yup that would be preferred

benedek 2018-05-21T17:52:32.000697Z

Also comments etc

Candid 2018-05-21T18:18:14.000717Z

it's a bit tricky since read and read-string only read one form

Candid 2018-05-21T18:18:21.000143Z

but can be done with something like this:

Candid 2018-05-21T18:18:50.000260Z

(defn try-read
  []
  (try (read)
    (catch Error e
      ::end)))

(loop [f (try-read)]
  (if (= ::end f)
    (println "done!")
    (do
      (pprint f)
      (recur (try-read)))))

Candid 2018-05-21T18:19:53.000185Z

and then running this script like joker read.joke < your-file.clj

Candid 2018-05-21T18:20:45.000658Z

note however that read will skip comments and autoexpand reader macros

Candid 2018-05-21T18:22:25.000272Z

for example, (map #(+ %1 %2) [1 2]) will be read as (map (fn [p__148# p__149#] (+ p__148# p__149#)) [1 2])

Candid 2018-05-21T18:23:50.000011Z

also, read doesn't parse the code, so you won't get an AST, just a soup of data structures representing the code

Candid 2018-05-21T18:24:34.000041Z

there is also undocumented parse__ function that does return AST, but it's half baked at best

Candid 2018-05-21T18:26:21.000363Z

(pprint (parse__ '(map #(+ %1 %2) [1 2]))) would print

Candid 2018-05-21T18:26:38.000153Z

{:type :call,
 :name "core/map",
 :callable {:type :var-ref,
            :var #'joker.core/map},
 :args [{:type :fn,
         :arities [{:type :arity,
                    :args [p__148#
                           p__149#],
                    :body [{:type :call,
                            :name "core/+",
                            :callable {:type :var-ref,
                                       :var #'joker.core/+},
                            :args [{:type :binding,
                                    :name p__148#}
                                   {:type :binding,
                                    :name p__149#}]}]}]}
        {:type :vector,
         :vector [{:type :literal,
                   :object 1}
                  {:type :literal,
                   :object 2}]}]}

benedek 2018-05-21T18:50:47.000520Z

Interesting. Will play with this tmrw. Thanks fornyour help!