2 ms·
Let's try to look at it in isolation. "parse-el" is used as a function, which takes one argument, the first argument when invoked from reduce (the accumulator)
by junke 9y ago
Let's try to look at it in isolation.
"parse-el" is used as a function, which takes one argument, the first argument when invoked from reduce (the accumulator), which is first [] then another vector (because of conj).
So "parse-seq" parses a sequence (named "form") and produces a vector, or nil. It applies "parse-el" to each form using reduce. When the result of any form gives a nil value, the whole result is also nil (see https://clojuredocs.org/clojure.core/reduced https://clojuredocs.org/clojure.core/reduced). The result is also nil if form is not sequential.
There is no other contract about "parse-el", it just should be able to "parse" whatever occurs in "form".
You could use it on your own with any kind of data that has a corresponding parse function.
A documentation string would have been nice, or different names ("parse-el"?)
Now, if you look at the usage of "parse-seq", you can see for example:
(let [vars* (parse-seq parse-variable vars)
....
And it looks like "parse-variable" parses a form and returns an instance of Variable.
(defn parse-variable [form]
(when (and (symbol? form)
(= (first (name form)) \?))
(Variable. form)))
- junke 9y ago"the first argument" => "the second argument"