O'Reilly logo

Functional Programming: A PragPub Anthology by Michael Swaine

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Make Life Simple for Your Callers

It gets even better.

If you know in advance some of the strategies your callers might want to pursue in dealing with an error, you can name those strategies at the point of a possible error, and then let callers select a strategy by name. The bind-continue form takes the name of a strategy, an argument list, and a form to implement the strategy.

So, continuing with our log example, you might choose to provide explicit skip and log strategies for dealing with a parse error:

 (defn parse-or-continue [logseq]
  (let [parse-log-entry
  (fn [entry]
  (with-handler (parse-log-entry entry)
  (bind-continue skip [msg]
  nil)
  (bind-continue log [msg]
  (println "****invalid log: " msg))))]
  (vec (map parse-log-entry ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required