Hi,

I'm seeking a small & idiomatic function that will take input and ensure 
it's wrapped in a list.  If nil, I'd like the list to be empty.  If the 
input is already a list, I don't want to wrap it in another list layer.  So:

  "hi"   => ("hi")
  nil    => ()
  ("hi") => ("hi")

 (list '("hi"))     => (("hi"))  ; bad
 (apply list "hi")  => (\h \i)   ; bad

So I've ended up writing the function with a conditional, like so.  Is 
there a tidier way?

(defn ls [x] (cond (list? x) (apply list x) 
                   (nil? x)  '() 
                   :else (list x)))

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

Reply via email to