You can see the special cases of nil, false, and true in the LispReader here if you're curious:
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LispReader.java#L393-L413 On Tue, Jan 29, 2019 at 4:45 PM Alex Miller <a...@puredanger.com> wrote: > > > On Tue, Jan 29, 2019 at 4:23 PM Rostislav Svoboda < > rostislav.svob...@gmail.com> wrote: > >> Hi Alex, >> >> > Sets are treated as predicate functions which are valid when they >> produce a logically true value. >> >> So then my question boils down to: >> Why is then (boolean (quote nil)) => false and (boolean (quote >> anything)) => true? >> > > nil, false, and true are the only three special "symbols" that the Clojure > reader reads as something other than a symbol. They are read as > respectively nil and boolean false and true. nil's "type" is nil (there is > no type to represent nil). false and true's type is java.lang.Boolean. > Moreover, the false and true values are exactly the static constants > java.lang.Boolean/FALSE and java.lang.Boolean/TRUE. > > quote's purpose is to read (with the Clojure reader, converting from > string to value) but NOT evaluate. For these three values, they all > evaluate to themselves, so quote has no effect. > > For something like (type (quote anything)), (quote anything) will read the > string "anything", and construct the symbol anything, with type > clojure.lang.Symbol. The quote prevents evaluation. > > Skipping some important details, every value in Clojure evaluates to > itself except for the two special cases of symbols and lists. Symbols > evaluate by looking up their associated value in the current namespace. > Lists evaluates its elements, then invokes the first element as a function > while passing the rest of the elements as arguments. > > So, no bug here. Everything is going as planned. :) > > >> And this boils down to: >> Why a type of quoted symbol (type (quote nil)) is nil and not >> clojure.lang.Symbol as is it the case for (type (quote anything))? >> Here the source says: >> (defn type >> "Returns the :type metadata of x, or its Class if none" >> {:added "1.0" >> :static true} >> [x] >> (or (get (meta x) :type) (class x))) >> >> And if I put few println's here, I see that in both cases (type (quote >> nil)), (type (quote anything)) the input arg x is nil, IOW the >> information "the arg x has a type of quoted symbol" is lost here. IOW >> the clojure.core/type eagerly reports the type of e.g.: >> (type (quote true)) => java.lang.Boolean >> (type (quote "foo")) => java.lang.String >> (type (quote nil)) => nil >> (type (quote 1)) => java.lang.Long >> etc. when I expect clojure.lang.Symbol, as for: >> (type (quote anything)) => clojure.lang.Symbol >> >> Hmm... *if* this type-hiding is a bug then I guess it's crawling too >> deeply to fix it, right? :) >> Anyway, thank you for your response, Alex! >> >> Bost >> >> >> Le mar. 29 janv. 2019 à 21:40, Alex Miller <a...@puredanger.com> a écrit >> : >> > >> > Sets are treated as predicate functions which are valid when they >> produce a logically true value. Sets with logically false values nil or >> false will fail this check. This is not a spec thing, but a general thing >> to be aware of in Clojure when using sets as functions. >> > >> > If you want nils, use (s/gen nil?). >> > If you want falses, use (s/gen false?). >> > If you want either, the simplest thing is probably (s/gen (s/nilable >> false?)), but keep in mind that the s/nilable generator is constructed to >> only produce nils 10% of the time, so you'll get 10% nils, 90% falses. >> > >> > You could also use the more cumbersome (s/gen (s/nonconforming (s/or :n >> nil? :f false?))) which should give you about 50/50 mix. >> > >> > >> > On Tuesday, January 29, 2019 at 2:23:50 PM UTC-6, Bost wrote: >> >> >> >> Could anybody explain please why I can't get a sample of falses or >> >> quoted nils / falses here? >> >> >> >> foo.core> (clojure-version) >> >> "1.10.0" >> >> foo.core> (require '[clojure.spec.gen.alpha :as gen] >> >> '[clojure.spec.alpha :as s]) >> >> nil >> >> foo.core> (gen/sample (s/gen #{'nil})) >> >> Error printing return value (ExceptionInfo) at >> >> clojure.test.check.generators/such-that-helper (generators.cljc:320). >> >> Couldn't satisfy such-that predicate after 100 tries. >> >> >> >> >> >> Other interesting and/or relevant cases are: >> >> >> >> foo.core> (gen/sample (s/gen #{'n})) >> >> (n n n n n n n n n n) >> >> foo.core> (gen/sample (s/gen #{true})) >> >> (true true true true true true true true true true) >> >> foo.core> (gen/sample (s/gen #{'true})) >> >> (true true true true true true true true true true) >> >> foo.core> (gen/sample (s/gen #{false})) >> >> Error printing return value (ExceptionInfo) at >> >> clojure.test.check.generators/such-that-helper (generators.cljc:320). >> >> Couldn't satisfy such-that predicate after 100 tries. >> >> foo.core> (gen/sample (s/gen #{'false})) >> >> Error printing return value (ExceptionInfo) at >> >> clojure.test.check.generators/such-that-helper (generators.cljc:320). >> >> Couldn't satisfy such-that predicate after 100 tries. >> >> foo.core> (gen/sample (s/gen #{nil})) >> >> Error printing return value (ExceptionInfo) at >> >> clojure.test.check.generators/such-that-helper (generators.cljc:320). >> >> Couldn't satisfy such-that predicate after 100 tries. >> >> >> >> >> >> Thanx >> > >> > -- >> > You received this message because you are subscribed to the Google >> > Groups "Clojure" group. >> > To post to this group, send email to clojure@googlegroups.com >> > Note that posts from new members are moderated - please be patient with >> your first post. >> > To unsubscribe from this group, send email to >> > clojure+unsubscr...@googlegroups.com >> > For more options, visit this group at >> > http://groups.google.com/group/clojure?hl=en >> > --- >> > You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> > To unsubscribe from this group and stop receiving emails from it, send >> an email to clojure+unsubscr...@googlegroups.com. >> > For more options, visit https://groups.google.com/d/optout. >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to clojure@googlegroups.com >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> clojure+unsubscr...@googlegroups.com >> For more options, visit this group at >> http://groups.google.com/group/clojure?hl=en >> --- >> You received this message because you are subscribed to a topic in the >> Google Groups "Clojure" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/clojure/K74chBn4Pis/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> clojure+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.