That worked - thank you!

On Tuesday, May 16, 2017 at 11:38:08 PM UTC-5, Alex Miller wrote:
>
> The problem here is that s/or is NOT a regex op and introduces a new level 
> of spec nesting. Try using s/alt (which IS a regex op) instead.
>
>
> On Tuesday, May 16, 2017 at 11:34:10 PM UTC-5, Alexander Sedgwick wrote:
>>
>> I'm looking to better understand how nested cats work (now that just 
>> sounds funny).
>>
>> I've found that sometimes spec/cat will generate a nested list:
>>
>> ```clojure
>> (gen/sample (s/gen (s/cat :start #{\a}
>>                                       :content (s/cat :nothing (s/? 
>> #{\^})
>>                                                             :fruit (s/or 
>> :apples (s/+ (s/cat :skin #{\s}
>>                                                                           
>>                              :flesh #{\f}
>>                                                                           
>>                              :core #{\c}))
>>                                                                           
>>  :bananas (s/+ #{\b})))
>>                                        :end #{\z})) 5)
>> ```
>> -> ((\a \^ (\s \f \c) \z) ... (\a \^ (\b \b) \z))
>>
>> Given the sample output we can assume this validate call will be false 
>> (provided flat list):
>>
>> ```clojure
>> (s/valid? (s/cat :start #{\a}
>>                        :content (s/cat :nothing (s/? #{\^})
>>                                              :fruit (s/or :apples (s/+ 
>> (s/cat :skin #{\s}
>>                                                                           
>>               :flesh #{\f}
>>                                                                           
>>               :core #{\c}))
>>                                                             :bananas (s/+ 
>> #{\b})))
>>                        :end #{\z}) [\a \^ \s \f \c \z])
>> ```
>> -> false
>>
>> I thought the s/spec function would need to be used to define nested 
>> structures (s/spec (s/cat ...)).
>>
>> Is this expected behavior or is there a better approach for working with 
>> flat lists?
>>
>> Thanks!
>>
>

-- 
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.

Reply via email to