> Such a specification looks a lot like a set of unit tests, though I'm > sure you may push it beyond. Thus, I think it might be nice if these > specification clauses could be set as metadata to the function as > well, and yet register to your check-on-load system. The > clojure.contrib.test-is library supplies such a framework whereby unit > tests may be specified either as function metadata or by themselves, > using macro deftest. > > Benoit
"defspec" does actually attach two pieces of metadata to the function... :spec => a no-arg function that, when executed, will return either true or throw an exception explaining which spec failed :specdoc => the specification in string form (easily vieable with the "specdoc" fn) I'm doing this for a couple of reasons. First of all, I really don't like having to come up with names for tests. Especially considering a specification (as I've defined it at least) clearly belongs to the function it represents. Another reason is that a big focus of this library is to make it easy to read and understand a specification (mostly as documentation of the function it represents). I toyed around with defining the spec in the metadata of the function directly, but it became pretty much unreadable in all but the most trivial cases... That being said, if somebody wanted to do that, there already exists a macro called "parse-specs" with the same arguments as "defspec", but which only returns the fn. This could easily be added to the metadata yourself... (in fact, if you look at the code, all defspec does is run that macro, attact the metadata, and optionally verify it) And the macro "verify-spec" will run the function in the :spec slot of any function. Another thing that I believe is important is to have your code be self verifying. For instance, by default, the simple act of loading the spec.clj file will verify that all the existing specifications are valid. (You can obviously disable this for performance reasons, but in general I think it's worth the extra sanity check). That also goes for the "specdoc" function. The action of viewing what the specification is will actually verify it as well. This way you can be sure that the spec you are looking actually represents reality. Chris --~--~---------~--~----~------------~-------~--~----~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---