Talk:Flatten a list: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 11: Line 11:
[1,2,3] + [] = [1,2,3]
[1,2,3] + [] = [1,2,3]
:::--[[User:Paddy3118|Paddy3118]] 06:35, 17 August 2009 (UTC)
:::--[[User:Paddy3118|Paddy3118]] 06:35, 17 August 2009 (UTC)
:::That's not the problem. The code performs the specified task, but the task is to do something that is usually considered a bad idea, and symptom of poor design elsewhere, in CL. --[[User:Kevin Reid|Kevin Reid]] 03:10, 17 October 2009 (UTC)


==OCaml and Empty lists?==
==OCaml and Empty lists?==

Revision as of 03:10, 17 October 2009

Common Lisp and Empty Lists?

The comment after the CL example seems to imply that it would not work with the example list given, which includes nested lists that contain an empty list. It would therefore not satisfy the task? --Paddy3118 00:50, 17 August 2009 (UTC)

It works with the example given. The point is that if your list-of-lists-of-...-of-lists has as one of the intended leaf values a list, you won't get the proper answer. This is true of any flattener, unless you mark the leaves as not-part-of-the-tree somehow. --Kevin Reid 02:32, 17 August 2009 (UTC)
Hi Kevin, The intent is for nests of ultimately empty lists to not appear in the output at all. Doesn't lisp have some operation OP, where:
  lista OP listb = lista with the elements of listb concatenated
And:
  lista OP emptylist == lista
You should be able to complete a solution from that. The Python recursive solution is like that as the OP is list summation where:
  [1,2,3] + [4,5,6] = [1,2,3,4,5,6]
And:
  [1,2,3] + [] = [1,2,3]
--Paddy3118 06:35, 17 August 2009 (UTC)
That's not the problem. The code performs the specified task, but the task is to do something that is usually considered a bad idea, and symptom of poor design elsewhere, in CL. --Kevin Reid 03:10, 17 October 2009 (UTC)

OCaml and Empty lists?

I am curious about the Ocaml entry and its problem with empty lists. Is their not some way of telling the type system to expect one or another of two types? Maybe wp:Algebraic data type (but I'm way out of my depth here) --Paddy3118 00:58, 17 August 2009 (UTC)

Doh! I have just seen the OCaml entry which has indeed been extended with an Algebraic data type solution, but sadly it misses the deep nesting around 6 and a deeply nested, but ultimately empty sub-list. --Paddy3118 06:45, 17 August 2009 (UTC)

Examples of use missing

It would be good if all the language examples show how to flatten the list mentioned in the task description. C++, Common Lisp, E, Erlang, and Slate don't do this and R doesn't show example output. --Paddy3118 02:36, 17 October 2009 (UTC)

Omit TI-89?

Should the TI-89 BASIC entry be changed to an omit from ...? And maybe the text moved to this talk page? --Paddy3118 02:36, 17 October 2009 (UTC)

Talk pages are for discussing the editing of the page, not additional content. (I also think that additional explanation of examples, as may have been done in a couple places, does not belong on talk pages.) As I wrote the entry I leave it to others to debate whether it should exist, but it definitely doesn't belong on the talk page. --Kevin Reid 03:02, 17 October 2009 (UTC)