Re: better flatten()?

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

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.

Considering that you apparently seem to be the original author of that phrase, and the delim functionality of flatten() itself in the first place, I think you would know that best. http://scm.openeuphoria.org/hg/euphoria/annotate/9f25f7612b39/include/std/sequence.e#l1803

(I would suggest modifying the docs to make that more explict in the future however: 'An optional delimiter to place after each flattened sub-sequence (except if the sub-sequence is the last element).')

DerekParnell said...

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

Agreed in full.

I am curious as to the rationale, though, of distinguishing between the two cases. That is, why should flatten() only insert a delimiter up to the last subsequence (or last element that is a sequence), and continue to append atomic elements after that without a delimiter? Seems to open the door to other kinds of weird cases. (E.g. if flatten() is passed a sequence that is already flat, and also given a delimiter, should merely return the original string or should it insert a delimiter between each of the atomic elements?)

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

Search



Quick Links

User menu

Not signed in.

Misc Menu