9

I can't publish a question because it's not up to the quality standard of the site

Why is it so bad? How can I improve it?

Here it is


I am trying to count words in a large file using the machinery from Iota (https://github.com/thebusby/iota#readme) just for an exercise.

I rewrote the frequencies function, that is based on reduce, to use reducers/fold

Here it is

(defn my-frequencies
"Returns a map from distinct items in coll to the number of times
they appear."

{:static true}
([] {nil 0}) ;;the case with no arguments

([coll] ;; the usual case
   (persistent!
    (fold
     (fn [counts x]
       (assoc! counts x (inc (get counts x 0))))
     (transient {}) coll)))
)

And then I have the usual passages:

(def mem-file (iota/vec "/home/me/my-file.txt"))

(defn words [line]
    (re-seq #"[a-z]+" line))

(def no-blank-lines (iota-filter identity mem-file))

(def seq-of-words (iota-mapcat words no-blank-lines))

here iota-filter is just an alias for clojure.core.reducers/filter and the same goes for iota-mapcat, it´s just an alias for clojure.core.reducers/mapcat

And now the last passage is

(defn freq-map [a-seq-of-words]
    (my-frequencies a-seq-of-words))

Now, when, at the REPL prompt I call freq-map, here´s what happens

withiota.core> (freq-map seq-of-words)
ArityException Wrong number of args (0) passed to: core$my-frequencies$fn      clojure.lang.AFn.throwArity (AFn.java:437)
withiota.core> 

But of course if I call my-frequencies with no arguments:

withiota.core> (my-frequencies)
{nil 0}
withiota.core> 

What's going on?

This Clojure reducers library - folding with max could be a relate dquestion but the case with my-frequencies called with 0 arguments is being taken care of, so I guess that question does not apply here


Thanks for any hint

17
  • 1
    I agree the question is mostly good, but you should use punctuation at the end of each sentence and capitalize the start. Apr 29, 2013 at 13:02
  • 13
    Expected: "Y code no wörkin??? 1eleven!". Found: Decent question. Baffled. Apr 29, 2013 at 13:06
  • 5
    Where is that notion coming from to use accents instead of an apostrophe? Apr 29, 2013 at 13:13
  • 7
    Could you add your proposed title too please?
    – Mat
    Apr 29, 2013 at 13:21
  • 6
    Please also add what tags you are using. Apr 29, 2013 at 13:24
  • 2
    They recently tweaked the quality filter threshhold for blocking questions, and I bet that's related. I know it puts a lot of weight on spelling, grammar, and punctuation, so try using full sentences with proper English instead of partial ones between your code blocks.
    – Rachel
    Apr 29, 2013 at 13:39
  • @Sulfurized Demonbobby: After your edit, it's hard to see if the code sections were formatted correctly. I think it's better to revert it.
    – interjay
    Apr 29, 2013 at 13:40
  • 1
    @Matt: Yeah, thought the same. Apr 29, 2013 at 13:42
  • @interjay: True, I can tell my monospace font from the regular without problems...might not be true for everyone and every setup. Apr 29, 2013 at 13:43
  • @Monolo: Oh, not obvious enough, next time suggest to use a better language instead, like PHP. ;) Apr 29, 2013 at 13:43
  • @Mat: Grrrrrrrr...thank you. Apr 29, 2013 at 13:45
  • @Bill The Lizard, the tags are clojure, reducers and fold Apr 29, 2013 at 13:52
  • @Mat The title was something along the lines of "Folding over frequencies" maybe it could have been "the zero argument case" ? Apr 29, 2013 at 13:53
  • @Sulfurized Demonbobby as for my accents, I am using a German keyboard and it seems that Germans know about ümläüts but not so much about accents. I can only type a properly accented á but nothing more Apr 29, 2013 at 13:56
  • 1
    let us continue this discussion in chat Apr 29, 2013 at 13:58

0

You must log in to answer this question.

Browse other questions tagged .