Subj : Re: any function to handle this kind of counting? To : comp.programming From : Peter Ammon Date : Sun Jul 31 2005 12:55 am Jon Harrop wrote: > Alex Fraser wrote: > >>>No, that is not similar to the OCaml I posted because the OCaml programs >>>are self-contained and either use lists (which are native to the >>>language) or data structures found in the OCaml stdlib. >> >>Why does that make a difference? > > > Having common definitions in a standard library is beneficial for many > reasons, primarily: > > 1. Stability (many relevant bits of OCaml's stdlib have been formally proven > correct using theorem provers and will have been used by many more people > than a "home grown" C implementation). I'd wager that more eyes have looked at something like the GLib C data structure library than at OCaml. > > 2. Generality (what happens if you want to combine two difference C programs > which use two different "home grown" set implementations?). If you want a library to support some task, you're going to find a lot more options in C than in OCaml. A data structure impedance mismatch is easier to deal with than a language mismatch. > > 3. Efficiency (a "home grown" set implementation in C is unlikely to match > the performance of OCaml's set implementation). Doubtful. OCaml is very fast, but it still targets the same instruction set as C, and there are very fast C libraries as well. > 4. Capability (OCaml's built-in hash function can traverse any data > structure). I don't understand what you mean by this. I have great respect for OCaml, but also for C; both are powerful and capable languages. For the record, here's how I'd do it in Cocoa/Objective-C, using a hash table: NSMutableDictionary* dict = [NSMutableDictionary dictionary]; NSEnumerator* enumer = [input objectEnumerator]; NSString* string; while ((string = [enumer nextObject])) [dict setObject:[NSNumber numberWithInt:1 + [[dict objectForKey:string] intValue]] forKey:string]; Certainly nothing approaching "hundreds of lines!" If anything, it's shorter than the OCaml approach. -Peter -- Pull out a splinter to reply. .