Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-14 Thread gaz jones
coincidentally, me and my brother wrote this while on the train to rubyconf last year: https://github.com/mikejones/mississippi havent put any docs or anything on there (its only a couple of functions), but is essentially a validation function that take a map (the thing to validate) and another m

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-12 Thread James Reeves
On 12 April 2011 22:04, Joost wrote: > For now, I think of the pretzel library as the lowest useful level of > abstraction for input tests. And for low level abstractions, I prefer > to place a higher value on correctness, extensibility, consistency and > possibly even performance (in roughly that

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-12 Thread Joost
I noticed I hadn't addressed this question earlier, so. On Apr 9, 3:48 am, James Reeves wrote: > The problem I have with such a scheme is that it seems more complex to > use in practise. For instance, let's say I wanted an optional value. > If predicates that fail a precondition return a truthy

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-12 Thread Joost
On Apr 12, 6:35 pm, James Reeves wrote: > On 12 April 2011 12:16, Joost wrote: > > > An input string of "foobar" is obviously not a number between 10 and > > 20, so whatever predicate you use to test for that should just return > > false. That not everybody here agrees on that indicates to me tha

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-12 Thread James Reeves
On 12 April 2011 12:16, Joost wrote: > An input string of "foobar" is obviously not a number between 10 and > 20, so whatever predicate you use to test for that should just return > false. That not everybody here agrees on that indicates to me that > people are trying to shove too much functionali

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-12 Thread Ken Wesson
On Tue, Apr 12, 2011 at 8:05 AM, James Reeves wrote: > On 12 April 2011 12:02, Ken Wesson wrote: >> Don't be ridiculous. If you're putting that (chain ...) sexp of yours >> in every separate place where a field is checked for being an integer >> in a range, then that's duplication. And if you ext

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-12 Thread James Reeves
On 12 April 2011 12:02, Ken Wesson wrote: > Don't be ridiculous. If you're putting that (chain ...) sexp of yours > in every separate place where a field is checked for being an integer > in a range, then that's duplication. And if you extract it into a > function that just takes the endpoints as

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-12 Thread Joost
All this stuff on complexity of validations is interesting, but my take on most of this (and especially on the pretzel functions) is that predicates should just test for validity, strictly if possible, and nothing else, since there are too many ways of combining these tests into more abstract funct

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-12 Thread Ken Wesson
On Tue, Apr 12, 2011 at 6:34 AM, James Reeves wrote: > On 12 April 2011 04:31, Ken Wesson wrote: >> There's a difference between the program parsing the same *object* >> multiple times, and the program's own source code containing >> duplication! > > But there isn't any duplication Don't be ridi

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-12 Thread James Reeves
On 12 April 2011 04:31, Ken Wesson wrote: > There's a difference between the program parsing the same *object* > multiple times, and the program's own source code containing > duplication! But there isn't any duplication: (defn present? [x] (not (string/blank? x))) (defn- parse-int [x] (try

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-11 Thread Ken Wesson
On Mon, Apr 11, 2011 at 10:23 PM, James Reeves wrote: > On 12 April 2011 01:41, Ken Wesson wrote: >> On Mon, Apr 11, 2011 at 7:09 PM, James Reeves >> wrote: >>> You wouldn't necessarily need to explicitly verify each precondition, >>> but it might be the case that the same string is parsed mult

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-11 Thread James Reeves
On 12 April 2011 01:41, Ken Wesson wrote: > On Mon, Apr 11, 2011 at 7:09 PM, James Reeves wrote: >> You wouldn't necessarily need to explicitly verify each precondition, >> but it might be the case that the same string is parsed multiple >> times. However, I'm unsure why you think this is a probl

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-11 Thread Ken Wesson
On Mon, Apr 11, 2011 at 7:09 PM, James Reeves wrote: > On 11 April 2011 21:26, Ken Wesson wrote: >> On Mon, Apr 11, 2011 at 1:09 PM, James Reeves >> wrote: >>> If you already have a, b, and c, then compounding them into one >>> function, only to then use a map to split them up again doesn't see

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-11 Thread James Reeves
On 11 April 2011 21:26, Ken Wesson wrote: > On Mon, Apr 11, 2011 at 1:09 PM, James Reeves wrote: >> If you already have a, b, and c, then compounding them into one >> function, only to then use a map to split them up again doesn't seem a >> good solution. > > The preconditions have to be checked.

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-11 Thread Ken Wesson
On Mon, Apr 11, 2011 at 1:09 PM, James Reeves wrote: > On 11 April 2011 09:43, Ken Wesson wrote: >> On Mon, Apr 11, 2011 at 4:12 AM, James Reeves >> wrote: >>> Yes, but remember that I said I was looking for non-compound >>> solutions. In my view, simple functions are more idiomatic Clojure. >>

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-11 Thread Ken Wesson
On Mon, Apr 11, 2011 at 7:17 AM, Meikel Brandmeyer wrote: > >> I do. And I also admit, that I think that someone not able to write a >> simple, non-critical application in a robust and fault tolerant way >> per default is a able to write a complex, critical application in a >> robust and fault tol

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-11 Thread James Reeves
On 11 April 2011 09:43, Ken Wesson wrote: > On Mon, Apr 11, 2011 at 4:12 AM, James Reeves wrote: >> Yes, but remember that I said I was looking for non-compound >> solutions. In my view, simple functions are more idiomatic Clojure. > > Mine were built up starting from very simple functions. Sure

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-11 Thread Meikel Brandmeyer
> I do. And I also admit, that I think that someone not able to write a > simple, non-critical application in a robust and fault tolerant way > per default is a able to write a complex, critical application in a > robust and fault tolerant way. Bleh. ... that I *don't* think ... -- You received

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-11 Thread Meikel Brandmeyer
Hi, On 11 Apr., 12:45, Ken Wesson wrote: > But you must admit that the mission-criticalness of robustness and > fault tolerance varies from one application to the next. I do. And I also admit, that I think that someone not able to write a simple, non-critical application in a robust and fault t

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-11 Thread Ken Wesson
On Mon, Apr 11, 2011 at 6:27 AM, Meikel Brandmeyer wrote: > Although not every system launches the Rockets, I'd prefer systems > with robustness and fault tolerance as default. Even if it's only the > egg clock gadget. But you must admit that the mission-criticalness of robustness and fault toler

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-11 Thread Ken Wesson
On Mon, Apr 11, 2011 at 5:29 AM, Meikel Brandmeyer wrote: > Hi, > > On 11 Apr., 11:16, Ken Wesson wrote: > >>> Just for illustration: Who designs a system, which starts an atomic >>> war on a bitflip in a test message? (Yeah, this happened and we are >>> only alive because of the gut feeling of a

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-11 Thread Meikel Brandmeyer
Hi, On 11 Apr., 12:04, Ken Wesson wrote: > So, similar incidents happened on both sides. And to illustrate this point: >> Because the phantasy of the average human being is quite limited. > > ? No one obviously imagined what happens when there is a malfunction in the hardware which might caus

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-11 Thread Ken Wesson
On Mon, Apr 11, 2011 at 5:07 AM, Meikel Brandmeyer wrote: >> What is your basis for this? > > Because the phantasy of the average human being is quite limited. ? > While a missed "this is allowed" might cause trouble, it doesn't > compromise the system. A missed "this is not allowed" however wil

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-11 Thread Meikel Brandmeyer
Hi, On 11 Apr., 11:16, Ken Wesson wrote: >> Just for illustration: Who designs a system, which starts an atomic >> war on a bitflip in a test message? (Yeah, this happened and we are >> only alive because of the gut feeling of an operator. > > Petrov? This was on the russian side. But it also h

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-11 Thread Meikel Brandmeyer
Hi, On 11 Apr., 10:43, Ken Wesson wrote: > What is your basis for this? Because the phantasy of the average human being is quite limited. While a missed "this is allowed" might cause trouble, it doesn't compromise the system. A missed "this is not allowed" however will. Solutions are not always

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-11 Thread Ken Wesson
On Mon, Apr 11, 2011 at 4:12 AM, James Reeves wrote: > On 11 April 2011 08:31, Ken Wesson wrote: >>> So your not-int-in-range? function is a compound function, made up of >>> four simple functions. >> >> So? This whole discussion arose because some of them have >> preconditions, like at-least 1 n

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-11 Thread James Reeves
On 11 April 2011 08:31, Ken Wesson wrote: >> So your not-int-in-range? function is a compound function, made up of >> four simple functions. > > So? This whole discussion arose because some of them have > preconditions, like at-least 1 not making sense for blank or > non-integer input. Yes, but r

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-11 Thread Ken Wesson
On Mon, Apr 11, 2011 at 3:09 AM, James Reeves wrote: > On 10 April 2011 22:24, Ken Wesson wrote: >> On Sun, Apr 10, 2011 at 1:37 PM, James Reeves >> wrote: >>> By adding error messages to predicates, we tightly couple the >>> validation error with the predicate, which in general is considered >

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-11 Thread James Reeves
On 10 April 2011 22:24, Ken Wesson wrote: > On Sun, Apr 10, 2011 at 1:37 PM, James Reeves wrote: >> By adding error messages to predicates, we tightly couple the >> validation error with the predicate, which in general is considered >> bad. However, this might be a valid compromise, but only if i

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-10 Thread Ken Wesson
On Sun, Apr 10, 2011 at 1:37 PM, James Reeves wrote: > By adding error messages to predicates, we tightly couple the > validation error with the predicate, which in general is considered > bad. However, this might be a valid compromise, but only if it > improves readability. I showed two posts ag

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-10 Thread James Reeves
On 10 April 2011 12:33, Ken Wesson wrote: > I thought you were the one who wanted the strings moved out to a data > structure that could be swapped with localized versions? :) Not really. I just want the error messages to be independent of the predicates. In essence, I'm looking for a solution w

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-10 Thread Ken Wesson
On Sun, Apr 10, 2011 at 11:42 AM, James Reeves wrote: > On 10 April 2011 09:49, Ken Wesson wrote: >> (def age-invalid-en >>  {:low "age must be at least 1" >>   :high "nobody is THAT old!" >>   :blank "age is required" >>   :non-integer "age must be a whole number"}) >> >> (def qty-invalid-en >>

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-10 Thread James Reeves
On 10 April 2011 09:49, Ken Wesson wrote: > (def age-invalid-en >  {:low "age must be at least 1" >   :high "nobody is THAT old!" >   :blank "age is required" >   :non-integer "age must be a whole number"}) > > (def qty-invalid-en >  {:low "quantity must be at least 1" >   :high "maximum 10 per cu

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-10 Thread Ken Wesson
On Sat, Apr 9, 2011 at 10:12 PM, James Reeves wrote: > On 9 April 2011 10:07, Ken Wesson wrote: >>> That particular example ties a predicate to a particular error >>> message. Error messages should be independent of predicates, otherwise >>> they can't be localized or changed to fit a specific si

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-09 Thread James Reeves
On 9 April 2011 10:07, Ken Wesson wrote: >> That particular example ties a predicate to a particular error >> message. Error messages should be independent of predicates, otherwise >> they can't be localized or changed to fit a specific situation. > > It can always be an integer or a keyword (or a

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-09 Thread Ken Wesson
On Sat, Apr 9, 2011 at 9:56 AM, James Reeves wrote: > On 8 April 2011 23:21, Ken Wesson wrote: >> Better yet: maybe we're looking at this backwards. Maybe what we want >> isn't a predicate for *passed* validation, but a predicate for >> *failed* validation: >> >> (defn s-blank? [x] >>  (if (empty

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-09 Thread James Reeves
On 8 April 2011 23:21, Ken Wesson wrote: > Better yet: maybe we're looking at this backwards. Maybe what we want > isn't a predicate for *passed* validation, but a predicate for > *failed* validation: > > (defn s-blank? [x] >  (if (empty? (.trim x)) "must not be blank")) That particular example t

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-08 Thread Ken Wesson
On Fri, Apr 8, 2011 at 9:48 PM, James Reeves wrote: > I'm saying that if a predicate is passed a value that doesn't match a > precondition, the predicate could return a truthy value, rather than > false. Better yet: maybe we're looking at this backwards. Maybe what we want isn't a predicate for *

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-08 Thread James Reeves
On 8 April 2011 08:43, Joost wrote: >> What about predicates that operate on numbers encoded as strings? e.g. >> "1" or "4.2". > > IMO, they should be in the strings package. The strings namespace could get rather large then, considering that strings are how most raw data is represented. > Sure,

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-08 Thread Joost
James Reeves wrote: > On 7 April 2011 20:03, Joost wrote: > > Yup. I'm mostly in the same boat. That's why all the predicates I've > > produced for now are in the pretzel.strings namespace. I expect to end > > up with few non-string predicates, but those will have to go into > > pretzel.numbers or

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-08 Thread James Reeves
On 7 April 2011 20:03, Joost wrote: > Yup. I'm mostly in the same boat. That's why all the predicates I've > produced for now are in the pretzel.strings namespace. I expect to end > up with few non-string predicates, but those will have to go into > pretzel.numbers or whatever make sense. What ab

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-07 Thread Joost
James Reeves wrote: > On 7 April 2011 06:48, Joost wrote: > > I think your choice of currying makes more sense, at least in the > > context of validations, so it might be a good idea to switch pretzel > > over to that scheme. > > Would it make sense for clj-decline? Yes. The main idea of clj-decl

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-07 Thread James Reeves
On 7 April 2011 06:48, Joost wrote: > I think your choice of currying makes more sense, at least in the > context of validations, so it might be a good idea to switch pretzel > over to that scheme. Would it make sense for clj-decline? The Valip predicates are designed with HTML form validation i

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-07 Thread Joost
On Apr 7, 1:47 am, James Reeves wrote: > I've been writing a small validation library, Valip, with a number of > included predicates. The predicates in Valip are curried if they have > more than one argument, but there is probably some overlap between > Valip and Pretzel, and it might be an idea

Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-06 Thread James Reeves
On 6 April 2011 13:27, Joost wrote: > The idea is to have a simple collection of these kinds of functions > outside of possibly unwanted frameworks. I'm using them myself for > doing validation with clj-decline, but it should at least be useful > for most code that has to deal with free-form text

Announcement: pretzel - a predicate library + call for suggestions

2011-04-06 Thread Joost
Hi, I've collected a bunch of predicate functions and bundled them up as pretzel: https://github.com/joodie/pretzel My main focus right now is towards string formatting predicates; tests for decimals, hex, email, urls, etc. Plus I've added some functions that combine predicates into new ones. Th