Re: better flatten()?

new topic     » goto parent     » topic index » view thread      » older message » newer message
petelomax said...
jimcbrown said...
DerekParnell said...

I don't know. I have not really had a need to use this function.

Why have the delim stuff in the first place? Euphoria generally doesn't follow the KISS principle, but I wonder if that's making the function overcomplicated. Does anybody use it?

I am beginning to think you might be quite right there, instead of flatten(s,delim) the programming construct to use should perhaps be join(flatten(s),delim), or often just join(s,delim).

Agreed in full.

petelomax said...

I was also thinking that flatten() should either have a "check for string elements" option or a sister function, at least that was until I did a quick search...

What would this sister function do?

petelomax said...

I was also thinking that flatten() should either have a "check for string elements" option or a sister function, at least that was until I did a quick search... I found the following uses of flatten() with a delimiter:

std\cmdline.e\build_commandline()    -- wants string handling, eg flatten({"del","filename"}," ") -> "del filename", rather than "d e l f i l e n a m e". 
redydemo\gui\objects\hypertext.e()   -- "" 
edita\eacons.ew (private routine)    -- "", for messagebox, eg flatten({"line1","line2"},"\n") -> "line1\nline2", rather than "l\ni\nn\ne\n1\nl\ni\nn\ne\n2" 
edita\eafext.ew ("")                 -- "" 
edita\eatabl.e ("")                  -- "" 

and only demo\net\pastey.ex without, which relies on \n being left in by read_lines() for something similar to eacons.ew above.

Surprisingly, all existing uses of flatten() that I could find were "sequence of string -> string", and all were really join() under a different name.

Pete

Yes, I think all those cases should be changed to replace the flatten() call with a join() call.

Maybe, a flatten(join(...)) call, in case (for example) a caller of build_commandline() passes in a sequence with more than a single sublevel (e.g. more depth than a mere sequence of strings). OTOH maybe we should just fail early in that case.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu