|
|
|
|
|
by LandR
2244 days ago
|
|
The clojure one to reverse a string makes it a sequence of characters, then reverses that sequence and puts it back together again as a string.. Why not jsut: (require '[clojure.string :as str])
(let [s "hello"]
(str/reverse s))
=> "olleh"
Reversing a string is in the core library... |
|
(The implementation of clojure.string/reverse) would only work on Clojure running on JVM. Clojure-clr, ClojureScript or any of the other ones, would use a difference implementation, not using StringBuilder. `(apply str (reverse s))` is then I guess "more" general across Clojure implementations. So Clojure is using StringBuilder, ClojureScript is using regexes + split to list + reverse + rejoin, ClojureCLR I'm not sure, but probably something C# specific.
But in the end, that's all semantics and the point is moot. Since Clojure is a pragmatic language, using an already defined function is obviously better, so no reason why you wouldn't use clojure.string/reverse, all the Clojure implementations have it exposed already.