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)))
))
psuedocode:
listmerge (list l1, list l2):
if l1 is empty, return l2
if l2 is empty return l1
if l1[0] is less than l2[0],
return l1[0] + listmerge(rest(l1), l2)
otherwise return l2[0] + listmerge(rest(l2), l1)
..... I see one thing. I could move that second cons statement out of
the 3rd if and put it as the return for the let.
I doubt it will help.
Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---