Earlier quoted context omitted.
> ... Clojure is fine (though any other Lisp would arguably be better than Clojure). Care to elaborate why you think any other Lisp is better than Clojure? I would like to hear your arguments.
Not the GP, but for quick things I prefer CL because: * TIMTOWTDI. Doing everything with map/reduce/filter is great, but sometimes it's more direct to just use the LOOP macro. Immutability is great, but sometimes it's way faster to just SETF something (and not have to worry about atoms). * Batteries (more) included. IME, I find myself needing to use third-party libraries sooner with Clojure than with CL. Also, QuickL…
Haskell vs. Clojure (2014)
41–50 of 55 posts
Re: Haskell vs. Clojure (2014)
#42Earlier quoted context omitted.
I mostly agree with you, but I think the out-of-the-box immutable data structures and sugar around around maps are very nice compared to the out-of-the-box scheme/racket experience.
I'm a fan of the out of the box immutable data structures and like the sugar, though you can get both in Lisp if you want. (Presumably Racket as well.) Lisp has everything, and more, though sometimes you have to work for it. I do enjoy Clojure's interop with the JVM, but that along with the community producing interesting things (this includes ClojureScript) are the primary reasons I care about Clojure at all. On the…
The whole point of benefiting from immutable data structures is their ubiquity. If they're something you reach for only when you personally decide you need them, they're unlikely to work well with 3rd-party code; you will have to do a lot more digging to understand how the code you're writing will behave in a concurrent context vs having it be obvious. Making it opt-in is almost making it pointless, unless you never use 3rd-party code.
Re: Haskell vs. Clojure (2014)
#43 http://jsbin.com/vikesu/edit?html,js,consoleRe: Haskell vs. Clojure (2014)
#44Earlier quoted context omitted.
Not the GP, but for quick things I prefer CL because: * TIMTOWTDI. Doing everything with map/reduce/filter is great, but sometimes it's more direct to just use the LOOP macro. Immutability is great, but sometimes it's way faster to just SETF something (and not have to worry about atoms). * Batteries (more) included. IME, I find myself needing to use third-party libraries sooner with Clojure than with CL. Also, QuickL…
I haven't used the LOOP macro in CL, but the for macro in Clojure is also very powerful and (imho) very readable. My take on the 'versify' example in 4 lines: (for [book book-order chapter (range 1 1000) :when (get-in bible [book (str chapter)]) verse (range 1 1000) :when (get-in bible [book (str chapter) (str verse)])] [book chapter verse (get-in bible [book (str chapter) (str verse)])]) Notice that a single "for" c…
One of such patterns is when I have to accumulate multiple kind of things while I zip through the input. Somewhat contrived example: You have a hashtable that maps integer key to a list of strings. You want to scan it just once and build two lists, strings associated with odd keys and strings associated with even keys.
;; populate input
(defvar input (make-hash-table :test 'eql))
(setf (gethash 1 input) '("ichi" "hi"))
(setf (gethash 2 input) '("ni" "fu"))
(setf (gethash 3 input) '("san" "mi"))
(setf (gethash 4 input) '("yon" "shi" "yo"))
(setf (gethash 5 input) '("go" "itsu"))
;; loop
(loop for k being each hash-key in input
when (oddp k) append (gethash k input) into odds
when (evenp k) append (gethash k input) into evens
finally (return (values odds evens)))
; => ("go" "itsu" "san" "mi" "ichi" "hi") and ("yon" "shi" "yo" "ni" "fu")Re: Haskell vs. Clojure (2014)
#45 #!/usr/bin/env amm
import $ivy.`com.typesafe.play::play-json:2.5.8`
import java.nio.file._, play.api.libs.json._
val bookOrder = Seq(
"Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy",
"Joshua", "Judges", "Ruth", "1 Samuel", "2 Samuel", "1 Kings", "2 Kings",
"1 Chronicles", "2 Chronicles", "Ezra", "Nehemiah", "Esther", "Job",
"Psalms", "Proverbs", "Ecclesiastes", "Song of Solomon", "Isaiah",
"Jeremiah", "Lamentations", "Ezekiel", "Daniel", "Hosea", "Joel", "Amos",
"Obadiah", "Jonah", "Micah", "Nahum", "Habakkuk", "Zephaniah", "Haggai",
"Zechariah", "Malachi", "Matthew", "Mark", "Luke", "John", "Acts",
"Romans", "1 Corinthians", "2 Corinthians", "Galatians", "Ephesians",
"Philippians", "Colossians", "1 Thessalonians", "2 Thessalonians",
"1 Timothy", "2 Timothy", "Titus", "Philemon", "Hebrews", "James",
"1 Peter", "2 Peter", "1 John", "2 John", "3 John", "Jude", "Revelation"
).zipWithIndex.toMap
val bible = Json.parse(Files.readAllBytes(Paths.get("ESV.json")))
.as[Map[String,Map[String,Map[String,String]]]]
val flattened = for((book, x) (bookOrder(b), c, v) }
println(result)
---Also, Python
#!/usr/bin/env python3
import json
books = [
"Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy",
"Joshua", "Judges", "Ruth", "1 Samuel", "2 Samuel", "1 Kings", "2 Kings",
"1 Chronicles", "2 Chronicles", "Ezra", "Nehemiah", "Esther", "Job",
"Psalms", "Proverbs", "Ecclesiastes", "Song of Solomon", "Isaiah",
"Jeremiah", "Lamentations", "Ezekiel", "Daniel", "Hosea", "Joel", "Amos",
"Obadiah", "Jonah", "Micah", "Nahum", "Habakkuk", "Zephaniah", "Haggai",
"Zechariah", "Malachi", "Matthew", "Mark", "Luke", "John", "Acts",
"Romans", "1 Corinthians", "2 Corinthians", "Galatians", "Ephesians",
"Philippians", "Colossians", "1 Thessalonians", "2 Thessalonians",
"1 Timothy", "2 Timothy", "Titus", "Philemon", "Hebrews", "James",
"1 Peter", "2 Peter", "1 John", "2 John", "3 John", "Jude", "Revelation"
]
books = {book:i for i, book in enumerate(books)}
with open('ESV.json') as f:
result = sorted(
((b, int(c), int(v), x) for b, x in json.load(f).items() for c, x in x.items() for v, x in x.items()),
key=lambda part: (books[part[0]], part[1:])
)
print(result)
---Glad we've put that to rest.
Re: Haskell vs. Clojure (2014)
#46Earlier quoted context omitted.
I mostly agree with you, but I think the out-of-the-box immutable data structures and sugar around around maps are very nice compared to the out-of-the-box scheme/racket experience.
I'm a fan of the out of the box immutable data structures and like the sugar, though you can get both in Lisp if you want. (Presumably Racket as well.) Lisp has everything, and more, though sometimes you have to work for it. I do enjoy Clojure's interop with the JVM, but that along with the community producing interesting things (this includes ClojureScript) are the primary reasons I care about Clojure at all. On the…
(0) The compiler can automatically perform optimizations like fusing small nodes and hash consing.
(1) The garbage collector can take advantage of the fact that traversing (the immutable portion of) the heap sequentially produces a topological sorting of the object graph.
Re: Haskell vs. Clojure (2014)
#47Earlier quoted context omitted.
I haven't used the LOOP macro in CL, but the for macro in Clojure is also very powerful and (imho) very readable. My take on the 'versify' example in 4 lines: (for [book book-order chapter (range 1 1000) :when (get-in bible [book (str chapter)]) verse (range 1 1000) :when (get-in bible [book (str chapter) (str verse)])] [book chapter verse (get-in bible [book (str chapter) (str verse)])]) Notice that a single "for" c…
I use CL/Scheme/Clojure at work. I generally prefer comprehension style ('for' in Clojure, srfi-42 in Scheme) but sometimes CL's loop let me save a few nestings. One of such patterns is when I have to accumulate multiple kind of things while I zip through the input. Somewhat contrived example: You have a hashtable that maps integer key to a list of strings. You want to scan it just once and build two lists, strings a…
1. You could add "using (hash-value v)" in the iteration clause to directly have the value (no gethash).
2. There is maphash too.
Re: Haskell vs. Clojure (2014)
#48Earlier quoted context omitted.
I use CL/Scheme/Clojure at work. I generally prefer comprehension style ('for' in Clojure, srfi-42 in Scheme) but sometimes CL's loop let me save a few nestings. One of such patterns is when I have to accumulate multiple kind of things while I zip through the input. Somewhat contrived example: You have a hashtable that maps integer key to a list of strings. You want to scan it just once and build two lists, strings a…
You surely know this but for other people interested: 1. You could add "using (hash-value v)" in the iteration clause to directly have the value (no gethash). 2. There is maphash too.
Re: Haskell vs. Clojure (2014)
#49Earlier quoted context omitted.
Not the GP, but for quick things I prefer CL because: * TIMTOWTDI. Doing everything with map/reduce/filter is great, but sometimes it's more direct to just use the LOOP macro. Immutability is great, but sometimes it's way faster to just SETF something (and not have to worry about atoms). * Batteries (more) included. IME, I find myself needing to use third-party libraries sooner with Clojure than with CL. Also, QuickL…
How is it more direct to use loop? As someone who has been writing production clojure for nearly 5 years I usually only see loop macro used by devs coming from oop because that's a more comfortable pattern for them. I have rarely needed to use it. As far as collections go, there's filter, remove, reduce, and various take functions. I don't see the deficiency. Debugging is still an issue, but I personally don't find i…
Re: Haskell vs. Clojure (2014)
#50Earlier quoted context omitted.
> ... Clojure is fine (though any other Lisp would arguably be better than Clojure). Care to elaborate why you think any other Lisp is better than Clojure? I would like to hear your arguments.
Clojure has neither the cool constructs of CL (CLOS, conditions) nor the minimal design and fantastic set of control primitives of Scheme. In fact it has no significant advantage over Scheme aside from running on the JVM, and a few disadvantages (recur, why TF are lambda lists vectors?, etc.). It's different enough to be weird and annoying, but the differences aren't advantageous enough to make me want to switch: Sch…
I actually really like recur because it signifies intent. It tells the future-me that I intended for this function to be tail recursive (ie, it not being tail-recursive should be considered an error).