Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Functional Programming is Gay

Name: Anonymous 2009-01-02 16:50

Yes, this is my homework

Define a Scheme function (count-elm L), that takes a list and returns a list with each element and its number of occurrences. For example:

>(count-elm '(a b c a a b c a b c a c d))
((a 5) (b 3) (c 4) (d 1))

I could have done this in seconds in C or something - what the fuck

Name: Anonymous 2009-01-02 18:15

>>1
My Scheme is awfully rusty (and by that, I mean I've never used it), but couldn't you use an associative list to store the return value? Use the list item as the key (in this case, a, b, c, etc.) and increase the value of each of those when you come across an instance of it.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List