(sorry for the repeat Nathan, this was meant to go to the list too)

On Thu, May 26, 2016 at 1:43 PM, Nathan Davis
<nda...@positronic-solutions.com> wrote:
> First off, I should say that you should first consider alternative
> approaches before considering the options below.  For example, cond seems
> well-suited for this particular case:
>
>
> (defn verify-position[pos type]
>  (cond (nil? pos)     true
>        (or (> pos 90)
>            (< pos 0)) false
>
>        .
>        .
>        .
>
>        :else true))

Yeah, cond is definitely useful here, but not in general.

> However, sometimes you really do want imperative-style control flow.  Two
> possibilities come to mind here:
>
> Monads (e.g., algo.monads)
> Continuations (e.g., pulley.cps)
>
> In fact, monads and (delimited) continuations are isomorphic.  The main
> difference is one of view-point -- the essence of monads is the composition
> of computations; the essence of continuations is control flow.
>
> For a monadic approach, I would start with something like the "Maybe" monad,
> but add a monadic 'bail' operator (to use your terminology and avoid
> conflicting with the common use of 'return' as one of the fundamental
> operators on monads).  Essentially, 'bail' would be constructed to abort the
> "current computation".  Then if you implement a function in terms of the
> 'bailing' monad (and encapsulate the effect to that function), you can use
> 'bail' to effectively return a value from the function at any point in the
> computation.
>
> With continuations, all you need is an "abortive" continuation back to the
> call-site of the function.  With pulley.cps, this is easily accomplished
> using call-cc / let-cc.  For example, here's your first example in terms of
> let-cc:

This was very informative.  I'm definitely going to write this down as
something to look into.  I think there's probably other and better
choices for input validation, but I can see this being extremely
useful for some of the equipment control work I do.

Thank you for the suggestion.

-John

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to