- Return some object. This is the canonical solution in objective and functional languages (which return "tuples").
- Use function parameters for the output. This is the canonical solution in Prolog.
- Allow functions to return multiple values. This is the canonical solution in Matlab.
Matlab's approach is beautiful, till you have to return up to 4 variables. Bu it does not scale to higher count of return values, because you have to address the output values by position - addressing by name does not work. And just a mental picture of me trying to read the 100th return value by writing the correct amount of commas and getting it wrong by one comma is painful.
Prolog's approach requires convention to differentiate between input parameters and output attributes.
Hence, the nicest approach, in my opinion, is to return "tuple", which can be addressed by both, position and name. This is the approach taken by R.
Žádné komentáře:
Okomentovat