Talk:Apply a callback to an array

From Rosetta Code
Revision as of 23:36, 15 January 2008 by rosettacode>TBH (→‎array vs list: Are tasks overspecified, or underspecified?)

The problem is, of course, that they're all doing slightly different things. To some extent this is unavoidable due to language differences, but when one example is mapping the results into another array and a different example decides to print them, that's just a bit sloppy. Though I certainly don't mind if you have secondary examples demonstrating different techniques or modifications to the basic premise (such as the c++ use of a binary function).

I wrote up some guidelines, but I need to make them more visible. I'll probably add them to--or link to them from--the programming task template.--Short Circuit 12:46, 23 January 2007 (EST)

array vs list

I was just looking at the Haskell solution for this task, and it uses a list instead of an array. Of course, Haskell has built in arrays, lists are just more natural, as they are in all functional languages. This seems deceptive to me. I know lists are more natural than arrays in Haskell, but it seems to me this page should contain the array example, and an alternate task should be made for lists. Just as Haskell will seem more complicated on the array examples, imperative languages like C will have to use a complicated list structure for the list examples. It doesn't seem right to neglect this distinction. Thoughts? -- Zarvok | Talk 22:45, 23 January 2007 (EST)

I don't know any functional languages. What's the difference between a list and an array? --Short Circuit 23:27, 23 January 2007 (EST)
TCL is almost-functional (it steals a lot from LISP). I'll put an example for either in there. A list is just what the name implies -- essentially what would be called a one-dimensional array in many other languages. It is the natural storage container for a bunch of data in TCL (and indeed was the only data structure for a long time). In TCL, at least, the notion of an "array" strictly implies an associate array. I.e. looping over a list means looping over the elements of the list (and doing something with them), but looping over an array means looping over the keys of the array (and doing something with the elements associated with those keys). Sgeier 18:28, 1 February 2007 (EST)
I still struggle with this differentiation, and what it may imply when providing examples in J, which is one of the languages where "a list" means "an array of one axis (or dimension)". If "list" means a unit of data that lacks any key-reference aspect, then perhaps tasks that specify use of lists should not be completed using J? --TBH 16:36, 15 January 2008 (MST)