(quote x) vs (Value x)

16 views
Skip to first unread message

Timo Mihaljov

unread,
Jan 22, 2015, 1:10:31 AM1/22/15
to clojure-c...@googlegroups.com
According to the API documentation [1], (quote x) should be equivalent to (Value x), but the the implementations are quite different:

    (defn parse-quote [[_ syn]]
      (cond
        ((some-fn number? keyword? symbol?) syn) {:op :singleton :val syn}
        (vector? syn) (parse-quoted-hvec syn)
        ; quoted map is a partial map with mandatory keys
        (map? syn) (syn-to-hmap syn nil nil false)
        :else (err/int-error (str "Invalid use of quote:" (pr-str syn)))))

    (defn parse-Value [[f & args :as syn]]
      (when-not (#{1} (count args))
        (err/int-error (str "Wrong arguments to Value: " syn)))
      {:op :singleton
       :val (first args)})

This means that e.g. '"Foo" results in an error, whereas (Value "Foo") is accepted.

I'd expect parse-quote to handle vectors and maps specially and handle the :else case exactly like Value. Should I create a ticket for this?

[1] http://clojure.github.io/core.typed/#clojure.core.typed/Val

--
Timo

Ambrose Bonnaire-Sergeant

unread,
Jan 22, 2015, 1:40:29 AM1/22/15
to core.typed
I would accept a patch that enforced

  (def valid-Value? (some-fn symbol? keyword? nil? con/boolean? number? character? string?))

in parse-Value in parse-unparse and parse-ast, and updated the documentation to note exactly what is supported.
It should also say what quote supports (ie. only symbols, keywords and numbers).

Thanks,
Ambrose

Ambrose Bonnaire-Sergeant

unread,
Jan 22, 2015, 1:44:35 AM1/22/15
to core.typed
It's probably also worth adding

true
false
nil

as syntax forms under the quote entry, as they don't exist anywhere else atm.

Thanks
Ambrose

Timo Mihaljov

unread,
Jan 22, 2015, 4:31:15 AM1/22/15
to clojure-c...@googlegroups.com
So quote should NOT support characters and strings, even though they are supported by Value? Is there a reason why it can't support everything that passes valid-Value?

--
Timo

Ambrose Bonnaire-Sergeant

unread,
Jan 22, 2015, 4:47:15 AM1/22/15
to core.typed
This is more about being conservative about valuable syntax real estate like quote, and not (yet) being convinced we
need more quote syntaxes.

Thanks,
Ambrose
Reply all
Reply to author
Forward
0 new messages