News for hackers. Stuff that matters.

SomeIdiot

Re:ClojureScript on Thursday July 21, 2011 @10:39AM (#2789659)
"ClojureScript does not currently support regular expression literals using #"" "

This one seems like a big deal, given how often I find myself using regexes in clojure. Is it on its way and is there a workaround currently?

Re:Haskell One Liners to Impress Your Friends on Saturday June 04, 2011 @04:47AM (#2619181)
Could you explain what it does?
Re:Scala One Liners on Thursday June 02, 2011 @07:57AM (#2611564)
1)

    (map #(* % 2) (range 1 10))
2)

    (reduce + (range 1 1000))
3)

    (def string "This is an example tweet talking about scala and sbt.")

    (some #(.contains string %) ["scala", "akka", "play framework", "sbt", "typesafe"])
4)

As a string:

    (slurp "filename")
As a list you could just do:

    (.split (slurp "filename") "\n")
Or if you want a lazy sequence:

    (line-seq (BufferedReader. (InputStreamReader. (FileInputStream. file-path) "UTF-8")))
There are also contrib libraries for this that do it nicer.

5)

    (apply prn (map #(str "Happy birthday" (if (= % 4) " dear NAME" " to you")) (range 1 5)))
6) I'm going to leave this blank for now. It's an easy enough problem, but I can't think of a way of doing it in a nifty one-liner.

Edit: Ahh thought of it now. group-by does it nicely:

    (group-by #(> % 60) [49, 58, 76, 82, 88, 90])
which returns a map with the elements keyed to the result of the anonymous function. In this case:

    {false [49 58], true [76 82 88 90]}
7) Something like

    (xml-seq (clojure.xml/parse the-xml))
probably.

8)

    (apply max [14, 35, -7, 46, 98])

    (apply min [14, 35, -7, 46, 98])
9) Clojure has pmap, which is used just like map is, work is just done in parallel. Also Clojure is known for its concurrency features, which I won't go over here.

10) I'm sure this can be done in a similar amount of code in Clojure, though I am not going to try.

Any comments/corrections are welcome.

Re:Boot a linux kernel right inside your browser. on Tuesday May 17, 2011 @07:27AM (#2556030)
So any interesting ideas for what this can be used for?
Re:Ask PG: Cost and effort of running Hacker News? on Wednesday April 15, 2009 @07:34AM (#563296)
Ah, well that explains it I guess :o)
Re:Ask PG: Cost and effort of running Hacker News? on Wednesday April 15, 2009 @07:03AM (#563274)
Why do you need to check in every 30 minutes?
Re:The Next Generation of Neural Networks [Google Tech Talk] on Saturday April 11, 2009 @06:33AM (#557406)
Do you know what the name of his/their team name is?
Re:VLC 0.9.9: The best media player just got better on Saturday April 04, 2009 @05:29AM (#546222)
Frankly the only reason I use it is because I don't know any better player. Not because it is that great. Any tips for good windows players?
Re:Hacker News RSS Feed + Readability on Wednesday April 01, 2009 @06:50PM (#542592)
Yeah, apostrophes seem to turn into some wierd jumble (e.g. ’) and so do other charaters. Aside from that, very nice work. Added to my reader.