On Jan 11, 5:53 pm, e <evier...@gmail.com> wrote:
> this seemed like a clean, nice way to merge to sorted lists into one
> sorted list.  I'm not getting clojure syntax, it seems:
>
> (defn listmerge [l1 l2]
>   (let [l1first (first l1) l2first (first l2)]
>     (if (= l1first nil) l2)
>     (if (= l2first nil) l1)
>     (if (< l1first l2first)
>       (cons l1first (listmerge (rest l1) l2))
>       (cons l2first (listmerge (rest l2) l1)))
>     ))

You need to nest the ifs, or use a cond:

(defn listmerge [l1 l2]
  (let [l1first (first l1) l2first (first l2)]
    (cond
      (empty? l1) l2
      (empty? l2) l1
      (< l1first l2first)
        (cons l1first (listmerge (rest l1) l2))
      :else
        (cons l2first (listmerge (rest l2) l1))))))

if statements in Clojure are inline, like the (x if y else z) syntax
in Python.

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