Re: better flatten()?

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

Here's my efforts ...

unfortunately this is what I get:

s = flatten({"abc",'x','y'}, ", ") 
-- s is "abc, xy" 

whereas I was expecting to see "abc, x, y", which is what my latest code above (just updated with a minor edit that did not change the outcome), Greg's, and my hastily-just-updated (which did change the result) version of Greg's code deliver.

Pete

I was going by the documentation in the current library one. It says 'An optional delimiter to place after each flattened sub-sequence (except the last one).' And as the source in your last example {"abc",'x','y'} has only one sub-sequence (the "abc"), I would have expected only one delimiter to be inserted. However, I do acknowledge that I interpreted the phrase (except the last one) to mean (except if the sub-sequence is the last element). Therefore I feel my code is producing what the original author has specified.

This why functional specifications are so important and extremely hard to write, often harder than implementing them in code.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu