Re: pre and post assertions, always in the meta data?

2022-02-15 Thread Sean Corfield
Whilst you solved your problem, you didn't get an answer about metadata.

There are multiple places metadata can appear in a function definition:

dev=> (defn ^{:one true} func (^{:two true} [x] {:three true} x) {:four 
true})
#'dev/func
dev=> (meta #'func)
{:one true, :arglists ([x]), :four true, :line 1, :column 1, :file 
"/home/seanc/.clojure/dev.clj", :name func, :ns 
#object[clojure.lang.Namespace 0x17b6ad97 "dev"]}
dev=> (->> #'func (meta) :arglists (mapv meta))
[{:two true, :three true}]
dev=>

I've delineated the arity of the function with ( ) for clarity so you can 
which metadata belongs to the function Var and which belongs to a specific 
arity, and you can see they are combined.

I've never seen anything except :pre/:post in position three and I've never 
seen :pre/:post in position two (until I saw your example from ostash.dev) 
-- but as you can see they are equivalent (and they combine).

I don't think I've ever seen function Var metadata in position four.
On Thursday, February 3, 2022 at 10:56:59 AM UTC-8 Laws wrote:

>
> I see this old post by Fogus:
>
> http://blog.fogus.me/2009/12/21/clojures-pre-and-post/
>
> With this example:
>
> (defn constrained–fn [f x]
>   {:pre  [(pos? x)]
>:post [(= % (* 2 x))]}
>   (f x))
>
> But I see this modern example:
>
> https://ostash.dev/posts/2021-07-01-pre-post-conditions/
>
> (defn func ^{:pre [(pos? x)] :post [(< % 100) (> % 1)]} [x] (+ 1 x))
>
> Where it is in the metadata. 
>
> But here I still the old style:
>
> https://clojure.org/reference/special_forms
>
> (defn constrained-sqr [x] {:pre [(pos? x)] :post [(> % 16), (< % 225)]} (* 
> x x))
>
> I was away from Clojure for a few years, so I think it I missed some of 
> its evolution. Is one of these styles favored? 
>
> I'm struggling with an issue where I cannot get the error to show up, even 
> when I deliberately send in data that would cause the assertion to return 
> false. 
>
> My function started: 
>
> (defn get-cisa-advisories
>   [cisa-advisory-urls]
>   {
>:pre [(set? cisa-advisory-urls)]
>:post [(vector? %)]
>}
>   (println "get-cisa-advisories")
>   (try
>
> When I called this with a vector, I got no error, but the app silently 
> died. I'm confused about this. The call to this function is wrapped in a 
> try/catch block, and that assertion must have thrown an error because that 
> is where the app dies, yet I couldn't see the exception in my catch block. 
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/3cc16f33-3f7b-49dd-96e8-b20fdb37e9cdn%40googlegroups.com.


Re: how do I debug a cryptic XML error?

2022-02-15 Thread Laws
Okay, this seemed to fix the problem:


cpe-dictionary (-> "official-cpe-dictionary_v2.3.xml"
   (java.io.FileInputStream.)
   (xml/parse))


xmlzipper (clojure.zip/xml-zip cpe-dictionary)

xmlnode (-> xmlzipper
zip/down
zip/right
zip/node)




On Tuesday, February 15, 2022 at 10:44:13 PM UTC-5 Laws wrote:

>
> I changed the code a bit:
>
> cpe-dictionary (-> "official-cpe-dictionary_v2.3.xml"
>(java.io.StringReader.)
>(xml/parse))
>
> xmlzipper (clojure.zip/xml-zip cpe-dictionary)
>
> Now I get this:
>
>   clojure.data.xml/*parse*   
> xml.clj:  84
>
>   clojure.data.xml/*parse*   
> xml.clj: 109
>
> clojure.data.xml.tree/*event-tree*
>   tree.clj:  70
>
>  clojure.core/*ffirst*
>   core.clj: 105
>
>   clojure.core/*first*
>   core.clj:  55
>
>  ...  
>  
>
>clojure.data.xml.tree/seq-tree/*fn*
>   tree.clj:  39
>
> clojure.core/*seq*
>   core.clj: 139
>
>  ...  
>  
>
>   clojure.data.xml.jvm.parse/pull-seq/*fn*   
>   parse.clj:  78
>
> com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next  
> XMLStreamReaderImpl.java: 652
>
> *javax.xml.stream.XMLStreamException*: *ParseError at [row,col]:[1,1]*
>
> * Message: Content is not allowed in 
> prolog.*
>
> *location*: 
> #object[com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl$1 
> 0x296bfddb "Line number = 1\nColumn number = 1\nSystem Id = null\nPublic Id 
> = null\nLocation Uri= null\nCharacterOffset = 0\n"]
>
>
>
>
> On Tuesday, February 15, 2022 at 7:50:12 PM UTC-5 Laws wrote:
>
>> So, I went to the government NVD website:
>>
>> https://nvd.nist.gov/products/cpe
>>
>> I downloaded the CPE Dictionary and unpacked it. It looks like standard 
>> XML. 
>>
>> I copy and paste the standard XML example given on the Clojure XML 
>> documentation page:
>>
>>  cpe-dictionary (-> "official-cpe-dictionary_v2.3.xml" io/resource 
>> io/file clj-xml/parse zip/xml-zip)
>>
>> I get:
>>
>> clojure.xml/*startparse-sax*xml.clj:  76
>> ...   
>>
>>jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke  
>> DelegatingMethodAccessorImpl.java:  43
>>
>>jdk.internal.reflect.NativeMethodAccessorImpl.invoke  
>> NativeMethodAccessorImpl.java:  77
>>
>>   jdk.internal.reflect.NativeMethodAccessorImpl.invoke0   
>> NativeMethodAccessorImpl.java
>>
>> com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse   
>>   SAXParserImpl.java: 317
>>
>> *java.lang.IllegalArgumentException*: 
>>
>>
>> I'm wondering, how do I figure out what is wrong here? I'm going to 
>> assume the government is offering reasonably standard XML, so where would 
>> the problem arise? How do I figure out a way around this? 
>>
>> The CPE dictionary is 386 megabytes so I can't share the hold file here, 
>> but when I run "head" on it, the beginning looks like this:
>>
>>
>> 
>>
>> http://scap.nist.gov/schema/configuration/0.1; 
>> xmlns="http://cpe.mitre.org/dictionary/2.0; xmlns:xsi="
>> http://www.w3.org/2001/XMLSchema-instance; xmlns:scap-core="
>> http://scap.nist.gov/schema/scap-core/0.3; xmlns:cpe-23="
>> http://scap.nist.gov/schema/cpe-extension/2.3; xmlns:ns6="
>> http://scap.nist.gov/schema/scap-core/0.1; xmlns:meta="
>> http://scap.nist.gov/schema/cpe-dictionary-metadata/0.2; 
>> xsi:schemaLocation="http://scap.nist.gov/schema/cpe-extension/2.3 
>> https://scap.nist.gov/schema/cpe/2.3/cpe-dictionary-extension_2.3.xsd 
>> http://cpe.mitre.org/dictionary/2.0 
>> https://scap.nist.gov/schema/cpe/2.3/cpe-dictionary_2.3.xsd 
>> http://scap.nist.gov/schema/cpe-dictionary-metadata/0.2 
>> https://scap.nist.gov/schema/cpe/2.1/cpe-dictionary-metadata_0.2.xsd 
>> http://scap.nist.gov/schema/scap-core/0.3 
>> https://scap.nist.gov/schema/nvd/scap-core_0.3.xsd 
>> http://scap.nist.gov/schema/configuration/0.1 
>> https://scap.nist.gov/schema/nvd/configuration_0.1.xsd 
>> http://scap.nist.gov/schema/scap-core/0.1 
>> https://scap.nist.gov/schema/nvd/scap-core_0.1.xsd;>
>>
>>   
>>
>> National Vulnerability Database (NVD)
>>
>> 4.9
>>
>> 2.3
>>
>> 2022-01-25T04:50:56.780Z
>>
>>   
>>
>>   > 

Re: how do I debug a cryptic XML error?

2022-02-15 Thread Laws

I changed the code a bit:

cpe-dictionary (-> "official-cpe-dictionary_v2.3.xml"
   (java.io.StringReader.)
   (xml/parse))

xmlzipper (clojure.zip/xml-zip cpe-dictionary)

Now I get this:

  clojure.data.xml/*parse* 
  xml.clj:  84

  clojure.data.xml/*parse* 
  xml.clj: 109

clojure.data.xml.tree/*event-tree*  
tree.clj:  70

 clojure.core/*ffirst*  
core.clj: 105

  clojure.core/*first*  
core.clj:  55

 ...
   

   clojure.data.xml.tree/seq-tree/*fn*  
tree.clj:  39

clojure.core/*seq*  
core.clj: 139

 ...
   

  clojure.data.xml.jvm.parse/pull-seq/*fn* 
parse.clj:  78

com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next  
XMLStreamReaderImpl.java: 652

*javax.xml.stream.XMLStreamException*: *ParseError at [row,col]:[1,1]*

* Message: Content is not allowed in 
prolog.*

*location*: 
#object[com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl$1 
0x296bfddb "Line number = 1\nColumn number = 1\nSystem Id = null\nPublic Id 
= null\nLocation Uri= null\nCharacterOffset = 0\n"]




On Tuesday, February 15, 2022 at 7:50:12 PM UTC-5 Laws wrote:

> So, I went to the government NVD website:
>
> https://nvd.nist.gov/products/cpe
>
> I downloaded the CPE Dictionary and unpacked it. It looks like standard 
> XML. 
>
> I copy and paste the standard XML example given on the Clojure XML 
> documentation page:
>
>  cpe-dictionary (-> "official-cpe-dictionary_v2.3.xml" io/resource io/file 
> clj-xml/parse zip/xml-zip)
>
> I get:
>
> clojure.xml/*startparse-sax*xml.clj:  76  
>   ...   
>
>jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke  
> DelegatingMethodAccessorImpl.java:  43
>
>jdk.internal.reflect.NativeMethodAccessorImpl.invoke  
> NativeMethodAccessorImpl.java:  77
>
>   jdk.internal.reflect.NativeMethodAccessorImpl.invoke0   
> NativeMethodAccessorImpl.java
>
> com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse   
>   SAXParserImpl.java: 317
>
> *java.lang.IllegalArgumentException*: 
>
>
> I'm wondering, how do I figure out what is wrong here? I'm going to assume 
> the government is offering reasonably standard XML, so where would the 
> problem arise? How do I figure out a way around this? 
>
> The CPE dictionary is 386 megabytes so I can't share the hold file here, 
> but when I run "head" on it, the beginning looks like this:
>
>
> 
>
> http://scap.nist.gov/schema/configuration/0.1; 
> xmlns="http://cpe.mitre.org/dictionary/2.0; xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance; xmlns:scap-core="
> http://scap.nist.gov/schema/scap-core/0.3; xmlns:cpe-23="
> http://scap.nist.gov/schema/cpe-extension/2.3; xmlns:ns6="
> http://scap.nist.gov/schema/scap-core/0.1; xmlns:meta="
> http://scap.nist.gov/schema/cpe-dictionary-metadata/0.2; 
> xsi:schemaLocation="http://scap.nist.gov/schema/cpe-extension/2.3 
> https://scap.nist.gov/schema/cpe/2.3/cpe-dictionary-extension_2.3.xsd 
> http://cpe.mitre.org/dictionary/2.0 
> https://scap.nist.gov/schema/cpe/2.3/cpe-dictionary_2.3.xsd 
> http://scap.nist.gov/schema/cpe-dictionary-metadata/0.2 
> https://scap.nist.gov/schema/cpe/2.1/cpe-dictionary-metadata_0.2.xsd 
> http://scap.nist.gov/schema/scap-core/0.3 
> https://scap.nist.gov/schema/nvd/scap-core_0.3.xsd 
> http://scap.nist.gov/schema/configuration/0.1 
> https://scap.nist.gov/schema/nvd/configuration_0.1.xsd 
> http://scap.nist.gov/schema/scap-core/0.1 
> https://scap.nist.gov/schema/nvd/scap-core_0.1.xsd;>
>
>   
>
> National Vulnerability Database (NVD)
>
> 4.9
>
> 2.3
>
> 2022-01-25T04:50:56.780Z
>
>   
>
>name="cpe:/a:%240.99_kindle_books_project:%240.99_kindle_books:6::~~~android~~">
>
> $0.99 Kindle Books project $0.99 Kindle Books 
> (aka com.kindle.books.for99) for android 6.0
>

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

how do I debug a cryptic XML error?

2022-02-15 Thread Laws
So, I went to the government NVD website:

https://nvd.nist.gov/products/cpe

I downloaded the CPE Dictionary and unpacked it. It looks like standard 
XML. 

I copy and paste the standard XML example given on the Clojure XML 
documentation page:

 cpe-dictionary (-> "official-cpe-dictionary_v2.3.xml" io/resource io/file 
clj-xml/parse zip/xml-zip)

I get:

clojure.xml/*startparse-sax*xml.clj:  76
...   

   jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke  
DelegatingMethodAccessorImpl.java:  43

   jdk.internal.reflect.NativeMethodAccessorImpl.invoke  
NativeMethodAccessorImpl.java:  77

  jdk.internal.reflect.NativeMethodAccessorImpl.invoke0   
NativeMethodAccessorImpl.java

com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse 
SAXParserImpl.java: 317

*java.lang.IllegalArgumentException*: 


I'm wondering, how do I figure out what is wrong here? I'm going to assume 
the government is offering reasonably standard XML, so where would the 
problem arise? How do I figure out a way around this? 

The CPE dictionary is 386 megabytes so I can't share the hold file here, 
but when I run "head" on it, the beginning looks like this:




http://scap.nist.gov/schema/configuration/0.1; 
xmlns="http://cpe.mitre.org/dictionary/2.0; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; 
xmlns:scap-core="http://scap.nist.gov/schema/scap-core/0.3; 
xmlns:cpe-23="http://scap.nist.gov/schema/cpe-extension/2.3; 
xmlns:ns6="http://scap.nist.gov/schema/scap-core/0.1; 
xmlns:meta="http://scap.nist.gov/schema/cpe-dictionary-metadata/0.2; 
xsi:schemaLocation="http://scap.nist.gov/schema/cpe-extension/2.3 
https://scap.nist.gov/schema/cpe/2.3/cpe-dictionary-extension_2.3.xsd 
http://cpe.mitre.org/dictionary/2.0 
https://scap.nist.gov/schema/cpe/2.3/cpe-dictionary_2.3.xsd 
http://scap.nist.gov/schema/cpe-dictionary-metadata/0.2 
https://scap.nist.gov/schema/cpe/2.1/cpe-dictionary-metadata_0.2.xsd 
http://scap.nist.gov/schema/scap-core/0.3 
https://scap.nist.gov/schema/nvd/scap-core_0.3.xsd 
http://scap.nist.gov/schema/configuration/0.1 
https://scap.nist.gov/schema/nvd/configuration_0.1.xsd 
http://scap.nist.gov/schema/scap-core/0.1 
https://scap.nist.gov/schema/nvd/scap-core_0.1.xsd;>

  

National Vulnerability Database (NVD)

4.9

2.3

2022-01-25T04:50:56.780Z

  

  

$0.99 Kindle Books project $0.99 Kindle Books 
(aka com.kindle.books.for99) for android 6.0

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/526fa490-4c26-46dc-acd3-34f377d1eb91n%40googlegroups.com.