-
Notifications
You must be signed in to change notification settings - Fork 3
Predicates
The following four are pretty self explanatory. Longer/shorter checks the length of a string. matches? passes if the given regex returns a result for the given input, and mismatches? is the opposite.
-
longer-than?:: Num -> fn -
shorter-than?:: Num -> fn -
matches?:: regex -> fn -
mismatches?:: regex -> fn
The file predicates expect a hunchentoot file tuple instead of a string, but act the same from the users' perspective. file-type? takes any number of type-strings and makes sure that the given files' content type matches one of them. You can find a list of common mimetypes here. It doesn't rely on file extensions. file-smaller-than? takes a number of bytes and checks if the given file is smaller.
-
file-type?:: [File-type-string] -> fn -
file-smaller-than?:: Size-in-bytes -> fn
You can define your own predicates if the above aren't sufficient. The formlets validation function expects a unary function that returns a boolean to figure things out (as always, "false" is represented by nil, () or '(), and "true" is any other value).
You can either pass lambdas in, as in (for example)
(lambda (f) (> (length f) 5)
or you can define a function to return such a predicate (this is how the default formlet predicates all work)
(defun longer-than? (num) (lambda (f) (> (length f) num)))
which you then pass into the form as (longer-than? 5) for the same effect as above. Check the Tutorial for more detail about how formlet declaration works.