Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
242 views
in Technique[技术] by (71.8m points)

recursion - StackOverFlowError Clojure change order of list

I want to be able to take a list in clojure like

(1 2 3 4 5 6 7 8 9) 

and change the order like this:

(9 8 7 6 5 4 3 2 1)

I could not find a built-in function for (inverting? Is that a good term?) turning lists back to front or whatever you wanna call the action, if there is I'd be very thankful if someone pointed that out since creating this function is not my goal it's just a step I need to pass to do what I really want to do. Anyway I wrote a function that should do it but I get this error:

StackOverflowError   clojure.core/seq (core.clj:133)

SOLVED: built-in function called reverse solves my problem, thanks!

    (defn turn-list
     ([l]
        (turn-list (rest l) (list (first l))))
     ([l1 l2]
        (if (empty? l1)
           l2
           (turn-list (conj l1 (first l2)) (rest l2)))))
question from:https://stackoverflow.com/questions/65598913/stackoverflowerror-clojure-change-order-of-list

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...