TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

List Comprehensions in Eight Lines of Clojure

109 pointsby davidbalbertover 12 years ago

7 comments

happy4crazyover 12 years ago
We don't address this in the post, but adding :while conditions is quite a fun challenge.<p>This is the best I could come up with (in Emacs Lisp): <a href="https://gist.github.com/4356261" rel="nofollow">https://gist.github.com/4356261</a> . It's rather hacky :D<p>Darius Bacon (abecedarius) came up with a beautiful alternative formulation that handles :while conditions seamlessly. Here's my port of his idea into Emacs Lisp: <a href="https://gist.github.com/4380866" rel="nofollow">https://gist.github.com/4380866</a><p>I'd be very happy to see other versions :)
评论 #4995262 未加载
philwelchover 12 years ago
&#62; Here's a question, though: If your language did not support list comprehensions, what would it take to add them? For a language like Ruby, you may have to dig into the language implementation itself.<p>No, not really:<p><a href="http://stackoverflow.com/questions/310426/list-comprehension-in-ruby" rel="nofollow">http://stackoverflow.com/questions/310426/list-comprehension...</a>
评论 #4994569 未加载
评论 #4996078 未加载
评论 #4996139 未加载
vselovedover 12 years ago
Gosh, if you had an extensible reader, you could do so much more... Oh wait, why don't we try it: <a href="http://lisp-univ-etc.blogspot.com/2013/01/real-list-comprehensions-in-lisp.html" rel="nofollow">http://lisp-univ-etc.blogspot.com/2013/01/real-list-comprehe...</a> ;)
评论 #4996690 未加载
aredingtonover 12 years ago
Someone's very happy to have authored Clojure's for special form.
评论 #4994414 未加载
评论 #4994413 未加载
评论 #4995783 未加载
评论 #4996383 未加载
krogerover 12 years ago
I nice and somewhat related paper is "Simple and Efficient Compilation of List Comprehension in Common Lisp" by Mario Latendresse:<p><a href="http://www.iro.umontreal.ca/~latendre/publications/listCompFinal.pdf" rel="nofollow">http://www.iro.umontreal.ca/~latendre/publications/listCompF...</a>
smegelover 12 years ago
Given that clojure is a dialect of lisp (the list processing language), it seems that list comprehensions should not be a remarkable achievement. Am i missing something?
评论 #4994499 未加载
dschiptsovover 12 years ago
This is very telling example of how differently Java people think.<p>First of all - ''this'' is NOT list comprehensions. Lisp has list comprehension, the sub-set of features that makes macros possible. Quote, back-quote, comma and grouping with parenthesis are parts of Lisp syntax to do it.<p>This is a meaningless generalization from a lisp programmer's perspective, just another macro.<p>Look at it carefully. This is the how confusion looks like. Thinking in terms of classes and methods prompts them to create artificial, unnecessary complications.<p>This is not hacking, this is exactly opposite.)
评论 #4996037 未加载
评论 #4996067 未加载