Re: Future of spec/explain-data, spec/and, etc.
On Sunday, July 24, 2016 at 10:40:41 PM UTC-5, Mars0i wrote: > > spec/explain-data seems very important. It allows programmatic responses > to spec failures. Maybe explain-data's behavior hasn't yet stabilized, > though? The structure of the return value has changed between 1.9.0-alpha7 > to the current 1.9.0-alpha10, the docstring is a bit vague, and the Spec > Guide only talks about it very briefly. > explain-data is not in flux but as we are in alpha, it could still change. :path are path tags :via are specs :in are data keys At present, it's easy to figure out which test(s) has/have failed by > examining the :path value(s) in explain-data's return value in some > situations, such as when specs are combined using spec/keys or spec/or. In > other situations--at least when specs are combined with spec/and, the:path > values are empty. Unlike spec/or, there's no way to specify keywords that > would identify the failed test. > > Am I right that explain-data is in flux? Is the goal that in the future, > it will always be possible for developers to specify composite specs in > such a way that explain-data can return info that identifies the failed > test clearly? For example, in the first spec/and illustration below, maybe > explain-data could use the names of the component specs as path elements? > (Or am I just confused about something?) > As specs, the component spec path is recorded in :via. > > Thanks- > > Example, using Clojure 1.9.0-alpha10: > > (s/def ::even even?) > (s/def ::zero-to-ten (s/int-in 0 10)) ; require number from 0 to 10 > inclusive > > user=> (s/explain-data (s/or :pred1 ::even :pred2 ::zero-to-ten) 11) > {:clojure.spec/problems > ({:path [:pred1], :pred even?, :val 11, :via [:user/even], :in []} > {:path [:pred2], >:pred (int-in-range? 0 10 %), >:val 11, >:via [:user/zero-to-ten], >:in []})} > > ;; Note that the format of the path entries are different above and below. > ;; Is there a reason for this difference, or will later versions return > ;; the same path elements? > Both examples seem consistent with my prior description of the data (specs in :via, paths in :path, and data keys in :in). They are specs with different structure so I would not expect them to yield the same explain results. > user=> (s/explain-data (s/keys :req-un [::even ::zero-to-ten]) {:even 11 > :zero-to-ten 11}) > {:clojure.spec/problems > ({:path [:even], :pred even?, :val 11, :via [:user/even], :in [:even]} > {:path [:zero-to-ten], >:pred (int-in-range? 0 10 %), >:val 11, >:via [:user/zero-to-ten], >:in [:zero-to-ten]})} > > ;; Here there's nothing in the :path or :in sequences, although :via > provides some information: > Yes, as expected. > user=> (s/explain-data (s/and ::even ::zero-to-ten) 11) > #:clojure.spec{:problems [{:path [], :pred even?, :val 11, :via > [:user/even], :in []}]} > > ;; Note that only the first failed test is identified, which makes sense. > > > ;; Another s/and example, with no info other than the value of :pred to > indicate what test failed: > What other info could be provided? You have the predicate and the invalid value. If you had named the predicate, you would have more info. user=> (s/explain-data (s/and even? (s/int-in 0 10)) 11) > #:clojure.spec{:problems [{:path [], :pred even?, :val 11, :via [], :in > []}]} > user=> (s/def ::even even?) :user/even user=> (s/def ::irange (s/int-in 0 10)) :user/irange user=> (s/explain-data (s/and ::even ::irange) 11) #:clojure.spec{:problems [{:path [], :pred even?, :val 11, :via [:user/even], :in []}]} -- 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.
Future of spec/explain-data, spec/and, etc.
spec/explain-data seems very important. It allows programmatic responses to spec failures. Maybe explain-data's behavior hasn't yet stabilized, though? The structure of the return value has changed between 1.9.0-alpha7 to the current 1.9.0-alpha10, the docstring is a bit vague, and the Spec Guide only talks about it very briefly. At present, it's easy to figure out which test(s) has/have failed by examining the :path value(s) in explain-data's return value in some situations, such as when specs are combined using spec/keys or spec/or. In other situations--at least when specs are combined with spec/and, the:path values are empty. Unlike spec/or, there's no way to specify keywords that would identify the failed test. Am I right that explain-data is in flux? Is the goal that in the future, it will always be possible for developers to specify composite specs in such a way that explain-data can return info that identifies the failed test clearly? For example, in the first spec/and illustration below, maybe explain-data could use the names of the component specs as path elements? (Or am I just confused about something?) Thanks- Example, using Clojure 1.9.0-alpha10: (s/def ::even even?) (s/def ::zero-to-ten (s/int-in 0 10)) ; require number from 0 to 10 inclusive user=> (s/explain-data (s/or :pred1 ::even :pred2 ::zero-to-ten) 11) {:clojure.spec/problems ({:path [:pred1], :pred even?, :val 11, :via [:user/even], :in []} {:path [:pred2], :pred (int-in-range? 0 10 %), :val 11, :via [:user/zero-to-ten], :in []})} ;; Note that the format of the path entries are different above and below. ;; Is there a reason for this difference, or will later versions return ;; the same path elements? user=> (s/explain-data (s/keys :req-un [::even ::zero-to-ten]) {:even 11 :zero-to-ten 11}) {:clojure.spec/problems ({:path [:even], :pred even?, :val 11, :via [:user/even], :in [:even]} {:path [:zero-to-ten], :pred (int-in-range? 0 10 %), :val 11, :via [:user/zero-to-ten], :in [:zero-to-ten]})} ;; Here there's nothing in the :path or :in sequences, although :via provides some information: user=> (s/explain-data (s/and ::even ::zero-to-ten) 11) #:clojure.spec{:problems [{:path [], :pred even?, :val 11, :via [:user/even], :in []}]} ;; Note that only the first failed test is identified, which makes sense. ;; Another s/and example, with no info other than the value of :pred to indicate what test failed: user=> (s/explain-data (s/and even? (s/int-in 0 10)) 11) #:clojure.spec{:problems [{:path [], :pred even?, :val 11, :via [], :in []}]} -- 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.
Re: Exception : cannot create ISeq from Long when empty list is present.. ?
"solve" is a recursive function that expects a collection of mazes to be returned. By adding "first" you change the return type, stripping off a layer each recursive call until you get integers instead of vectors. - James On 24 July 2016 at 08:32, Ashish Negi wrote: > the code throwing exceptions is below it : > https://github.com/ashishnegi/joy-of-clojure/blob/master/src/joy_of_clojure/chap16_thinking_programs.clj#L76 > > -- > 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 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.
Re: Exception : cannot create ISeq from Long when empty list is present.. ?
the code throwing exceptions is below it : https://github.com/ashishnegi/joy-of-clojure/blob/master/src/joy_of_clojure/chap16_thinking_programs.clj#L76 -- 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.
Exception : cannot create ISeq from Long when empty list is present.. ?
I am writing a soduku solver.. Everything works but since i am interested in first solution.. when i write `first` after https://github.com/ashishnegi/joy-of-clojure/blob/master/src/joy_of_clojure/chap16_thinking_programs.clj#L58 I get {:type java.lang.IllegalArgumentException ;; :message "Don't know how to create ISeq from: java.lang.Long" ;; :at [clojure.lang.RT seqFrom "RT.java" 542]} though printing the argument gives me.. ; "value: " () " class: " clojure.lang.LazySeq at https://github.com/ashishnegi/joy-of-clojure/blob/master/src/joy_of_clojure/chap16_thinking_programs.clj#L786 Please see full stack trace at : https://github.com/ashishnegi/joy-of-clojure/blob/master/src/joy_of_clojure/chap16_thinking_programs.clj#L88 -- 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.