count not supported on this type

734 views
Skip to first unread message

Roelof Wobben

unread,
May 9, 2014, 12:42:37 PM5/9/14
to clo...@googlegroups.com
I try to make this assigment :

Write the function (contains-duplicates? sequence) that takes a sequence as a parameter and returns true if sequence contains some element multiple times. Otherwise it returns false.

So I did this :

(defn contains-duplicates? [a-seq]
  (let [element (fn element [a-seq] (count a-seq) )]
     (= (map element a-seq)1)))

But then I see this message : UnsupportedOperationException count not supported on this type: Long  clojure.lang.RT.countFrom (RT.java:556)

When I change map to apply I see this message : ArityException Wrong number of args (5) passed to: structured-data$contains-duplicates-QMARK-$element  clojure.lang.AFn.throwArity (AFn.java:437)

Where did I misunderstood this page : http://iloveponies.github.io/120-hour-epic-sax-marathon/structured-data.html

Roelof

James Reeves

unread,
May 9, 2014, 2:24:29 PM5/9/14
to clo...@googlegroups.com
Your function is essentially:

    (= (map count coll) 1)

So you're applying the function "count" to each element in the collection. Let's say your collection is:

    [1 2 3]

Then you're trying to evaluate:

    [(count 1) (count 2) (count 3)]

Clojure is raising an exception that says "I can't count a number, I can only count collections".

- James


--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Roelof Wobben

unread,
May 9, 2014, 3:15:53 PM5/9/14
to clo...@googlegroups.com, ja...@booleanknot.com
oke,

Then I have to fnd another way to see how many times a number is present in a collection.
I thought count  could do that.

Roelof


Op vrijdag 9 mei 2014 20:24:29 UTC+2 schreef James Reeves:
Reply all
Reply to author
Forward
0 new messages