I tried out your example with a couple of files and it appeared to
work.  Is it supposed to fail, or is this an example of what you had
to do to work around the problem you mentioned?

It's certainly ok for a function to return different data types.  I
guess the simplest example of that would be the identity function.

user=> (identity 5)
5
user=> (identity "x")
"x"

Here is another one:

user=> (defn return-string-or-num [flag] (if flag "x" 0))
#'user/return-string-or-num
user=> (return-string-or-num :t)
"x"
user=> (return-string-or-num nil)
0

Here is an example of using that function with recur:

user=> (loop [x 0
       count 0]
  (println "x=" x "x is a" (class x) "count=" count)
  (if (< count 10)
    (recur (return-string-or-num (even? count))
           (inc count))))
x= 0 x is a java.lang.Integer count= 0
x= x x is a java.lang.String count= 1
x= 0 x is a java.lang.Integer count= 2
x= x x is a java.lang.String count= 3
x= 0 x is a java.lang.Integer count= 4
x= x x is a java.lang.String count= 5
x= 0 x is a java.lang.Integer count= 6
x= x x is a java.lang.String count= 7
x= 0 x is a java.lang.Integer count= 8
x= x x is a java.lang.String count= 9
x= 0 x is a java.lang.Integer count= 10
nil
user=>

-- 
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

Reply via email to