On Thursday, March 8, 2012 2:19:37 PM UTC-8, mefesto wrote:
>
> If `x` is a list then is the call to `(apply list x)` necessary?
>
Yes, meant to take that out.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojur
Not sure what kind of input you can get, but apply-ing list only on strings
would decompose them, so your function can be written as:
(defn ls [x]
(cond
(string? x)
(apply list (list x))
:else
(apply list x
as '(apply list nil)' will yield '().
Or, you can write i
> 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)))
If `x` is a list then is the call to `(apply list x)` necessary?
(defn ls [x]
(
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"))