Commits

Anonymous committed b26c5cf

updates to Chapter 2 - cover Clj-MiscUtil 0.3

  • Participants
  • Parent commits 8e70fa0

Comments (0)

Files changed (1)

File src/docbkx/bituf-handbook.xml

   (throw (NullPointerException. "dummy")))</programlisting>
 
       </sect2>
+      
+      <sect2>
+        <title>Retry on exception <db:literal>{:added "0.3"}</db:literal></title>
+        
+        <para>Occasionally we want to retry an operation few times before giving
+        up. <db:literal>try-while</db:literal> and <db:literal>try-times</db:literal>
+        serve this purpose based on condition and number-of-times respectively.
+        <db:literal>try-while</db:literal> takes a predicate function and body
+        of code - the code body is executed repeatedly until it throws no
+        exception or the predicate returns false. <db:literal>try-times</db:literal>
+        accepts a positive integer and body of code, which is tried at most
+        the specified number of times.</para>
+        
+        <db:programlisting>(def a (atom 0))
+
+(defn foo
+  "The function we want tried several times"
+  []
+  (do (swap! a inc)
+    (if (&lt; @a 5) (throw (NullPointerException.))
+      (+ 10 @a))))
+
+(try-while (fn [^Throwable e] (&lt; @a 7))
+  (foo))
+
+(try-times 7
+  (foo))</db:programlisting>
+      </sect2>
     </sect1>
 
     <sect1>
               
               <entry>string</entry>
               
-              <entry nameend="c4" namest="c3">Picks filename from a given
-              filepath</entry>
+              <entry nameend="c4" namest="c3">Picks filename (with extension)
+              from a given filepath</entry>
+            </row>
+            
+            <row>
+              <entry><literal>split-filename</literal> {:added "0.3"}</entry>
+              
+              <entry>vector of 2 string elements</entry>
+              
+              <entry nameend="c4" namest="c3">Splits filename as file name
+              and file extension and returns a vector containing both</entry>
+            </row>
+            
+            <row>
+              <entry><literal>pick-filename-name</literal> {:added "0.3"}</entry>
+              
+              <entry>string</entry>
+              
+              <entry nameend="c4" namest="c3">Picks only the file name (without
+              extension) portion from a given filepath</entry>
+            </row>
+            
+            <row>
+              <entry><literal>pick-filename-ext</literal> {:added "0.3"}</entry>
+              
+              <entry>string</entry>
+              
+              <entry nameend="c4" namest="c3">Picks only the file extension from
+              a given filepath</entry>
             </row>
             
             <row>