Programming Idioms
programming-idioms.org
Programming Idioms
1–10 of 19 posts
Re: Programming Idioms
#2Re: Programming Idioms
#3Re: Programming Idioms
#4Re: Programming Idioms
#5 Sorry, [Common Lisp] is currently not a supported language.
New time sink avoided.Re: Programming Idioms
#6Re: Programming Idioms
#7Why not jsut:
(require '[clojure.string :as str])
(let [s "hello"]
(str/reverse s))
=> "olleh"
Reversing a string is in the core library...Re: Programming Idioms
#8These kinds of collections can be nice, but I think it’s fair to warn against looking at them too closely. Sometimes they’re not actually idiomatic and often the implementations have differences in them that see non-obvious.
lines = open(f).read()
which doesn't close the file. The second C example of this task is tricky, and seems to miss an offset.The C and Go implementations of uniform random integer include the upper limit, the Python and Rust implementations don't.
And that's just from quickly browsing.
Re: Programming Idioms
#9Re: Programming Idioms
#10The 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.