Talk:Apply a callback to an array: Difference between revisions

From Rosetta Code
Content added Content deleted
No edit summary
Line 8: Line 8:


:I don't know any functional languages. What's the difference between a list and an array? --[[User:Short Circuit|Short Circuit]] 23:27, 23 January 2007 (EST)
:I don't know any functional languages. What's the difference between a list and an array? --[[User:Short Circuit|Short Circuit]] 23:27, 23 January 2007 (EST)

::TCL is almost-functional (it steals a lot from LISP). I'll but 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 <i>associate</i> 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 <i>keys</i> of the array (and doing something with the elements associated with those keys).

Revision as of 06:59, 1 February 2007

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 but 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).