On 5/26/16, 7:50 AM, "John Szakmeister" <[email protected] on behalf of
[email protected]> wrote:
>def verify_position(pos, type):
> # It's acceptable to have a None value--it just means don't
> # change the position for the axis.
> if pos is None:
> return True
>
> # Anything outside our limits is invalid.
> if (pos > 90) or (pos < 0):
> return False
>
> if type == 'switched' and pos not in (0, 90):
> # Switched axes only allow 0 and 90, and nothing in
> # between.
> return False
>
> if type == 'dual':
> # We can't control the value on this axis, so anything
> # other than None is invalid.
> return False
>
> return True
(defn verify-position [pos type]
(cond (nil? pos) true
(or (> pos 90) (< pos 0)) false
(and (= type “switched”)
(not (in-range pos 0 90))) false
(= type “dual”) false
:else true))
(or :else (do-stuff-to-verified-position pos type) if that branch is more
complex?)
A pattern that I’ve also started using is something like this:
(defn guarded-process [data]
(some-> data
first-guard
second-guard
(another-guard :with “parameters”)
(process-the-data 1 2 3 4)))
That works well for a process that operates on non-nil data and then you write
the guards to return the data if it’s valid or nil if it isn’t.
Sean Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
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
---
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 [email protected].
For more options, visit https://groups.google.com/d/optout.