Talk:Symmetric difference: Difference between revisions

Content added Content deleted
(→‎Set type: Obvoius or not...)
Line 61: Line 61:
:::::''If input types are being substituted then is it obvious that any input lists should/should not have duplicates and should/should not have an order imposed for the algorithm to work? ''
:::::''If input types are being substituted then is it obvious that any input lists should/should not have duplicates and should/should not have an order imposed for the algorithm to work? ''
:::::Obvious or not, the concern can be resolved by simply noting the caveat in each language's example area, rather than requiring that a workaround be demonstrated in code. --[[User:Short Circuit|Michael Mol]] 13:44, 10 February 2010 (UTC)
:::::Obvious or not, the concern can be resolved by simply noting the caveat in each language's example area, rather than requiring that a workaround be demonstrated in code. --[[User:Short Circuit|Michael Mol]] 13:44, 10 February 2010 (UTC)

:: Paddy3118 wrote:<br />
:::> Oh, I don't think it is hard to do, I just think that because we are dealing with sets then it <br />
:::> isn't right to have the chance of duplicates in outputs.

::My programming philosopy would be that if the purpose of the function is to return the symmetric difference of two sets, then it is an error to call the function with a list containing duplicate elmeents. The result of calling a function with invalid arguments is undefined, and the function can do whatever it pleases, including withdrawing all the money in your banking accounts. The symmetric difference function is not in error, the calling function is in error.

::Now, however, if the stated function is to convert the inputs to sets, and return the symmetric difference of the sets, the function should do just that, and duplicate elements in each list are allowed as valid inputs. It's a matter of what you defining as the purpose of your function.

::Furthermore, you can define a function to return the symmetric difference of two sets if two sets are provided as input, or to throw an exception if lists are provided (containing one or more duplicates). This is a different definition of the function, and it's definition includes lists containing duplicate elements as valid inputs to the functon. Just that it's response is different than if two valid sets were provided as inputs.--[[User:Rldrenth|Rldrenth]] 16:43, 10 February 2010 (UTC)