Talk:Flatten a list

From Rosetta Code

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)

OK, I've now added the code to show flattening the given list in C++ (I already had written it anyway, because I needed it to test the algorithm). I guess you can see why I originally didn't. --Ce 08:14, 17 October 2009 (UTC)

Any more for any more? I note that the new Clojure example doesn't show the flattening applied to the example mentioned in the task either. Thnks, --Paddy3118 18:32, 20 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)

Line drawing in web browsers (J solution)

Out of interest which browser/platform combinations are not correctly displaying the line drawing in the J solution?

I tested the display of the line drawing characters on IE 8 (Windows 7) and Firefox 3.63 (Windows 7 and Ubuntu) and they display fine there. --Tikkanz 00:02, 2 June 2010 (UTC)

Just tried Google Chrome version 5.0.375.55 which was OK. --Paddy3118 00:47, 2 June 2010 (UTC)
While the current display looks fine on most of the systems I tested it on, it looks wrong in Google Chrome 5.0.375.55 running on Vista. --Rdm 02:33, 3 June 2010 (UTC)
Put the box into J highlighting again and it gets ugly since the digits are highlighted by GeSHi to be bold. That makes them wider than the surrounding characters, which throws off vertical line alignment. I have no clue what font the <pre> blocks are using; if I set them manually to Consolas or Courier New it all works fine. Ah, apparently it's Lucida Console. This probably can be fixed in the MW style sheet, considering that Lucida COnsole is the default choice for IE 8 at least for Latin monospace. There seem to be some fonts that work and some that don't. I agree, though, that everything should be in a single block. I made that change more of pragmatic considerations. In any case, a few sample images: Consolas, Courier New, DejaVu Sans Mono, Lucida Console – that's all I have in monospaced fonts. Note that Consolas didn't have line-drawing glyphs in Vista; dunno whether that has been fixed in an update or so, but Windows 7's Consolas has them. Seemingly only Lucida Console has a different width depending on the weight, though (which makes it even more unsuitable as the default). —Johannes Rössel 08:32, 2 June 2010 (UTC)
If I put something in the RC global stylesheet for 'pre', I don't want to name a font that may be platform-specific. Is there a font (say, "Courier" or "Monospace") that works across platforms? Alternately, I could use some free-license webfont, if folks can agree on one. --Michael Mol 12:18, 2 June 2010 (UTC)
I have no idea whether there are such fonts. Windows itself comes with Lucida Console, Courier New and Consolas (as well as a bunch of CJK fonts which are not really meant to be used in Latin-only contexts [at least, judging from the looks of their Latin glyphs]). Linux and similar systems tend to have fonts with quite creative names, such as Mono, Sans or Serif – I have no clue whether that are the actual names of the typefaces or merely aliases for fonts one actually might know.
In any case, you can list a number of typefaces in decreasing order of preference which is pretty common practice. The keyword "monospace" refers to a non-specific (user-defined) monospaced font (which is what's currently used, apparently – either intentionally or just by not redefining font-family on <pre> – but that runs into the problem with Lucida Console at least with IE on Windows). So you could, theoretically, give a long list of fonts that are known to work and present on most, if not all systems. Downloadable fonts (WOFF, EOT, etc.) may be a last resort option but for a single language probably way overkill. Another possibility would be to tweak J syntax highlighting that numbers in boxes are no longer rendered in boldface. —Johannes Rössel 20:53, 3 June 2010 (UTC)
On that 64 bit vista system, running Chrome, text which is not bolded still looks wrong. For example: Compile-time_calculation#J. (It looks fine in IE. I did not install firefox.) Anyways, it is not clear that bold is the issue. --Rdm 11:55, 4 June 2010 (UTC)

Vandalization-like modification to C code

Take a look at the history and the C code. It seems it was removed a correct implementation, replaced or "prefixed" with a imagined silly conversation, and then replaced with a code that works on the ASCII representation of (non generic) list, but it is no way useful to flatten a real and "general" list held in memory; to me that code does not solve the task, since the ASCII representation of a list is not what we usually have when dealing with lists; the previous removed code did. I'll fix it back if no strong motivation for keeping the current silly and simplistic tricky implementation is given. --ShinTakezou 10:15, 1 October 2010 (UTC)

+1 on putting the original code back, but I'm not so sure it was vandalism - maybe an over-enthusiastic mod by someone who hasn't lurked enough? --Paddy3118 11:11, 1 October 2010 (UTC)
Actually, if someone were to wrtie a corresponding Tree traversal routine, in C, that took in the string "[1,[2,[4,7],5],[3,[6,8,9]]]" which is a nested list representation of the example tree, then, but only then, the disputed C routine for list flattening gains merit. --Paddy3118 13:55, 1 October 2010 (UTC)
I vote change it back, if it's incorrect. I think it's possible that the editor doesn't understand what a list is. (He may have been going for a "clever" solution; I doubt it was meant as vandalism, else he probably wouldn't have created a user account.) -- Erik Siers 14:56, 1 October 2010 (UTC)