While I was reading about the array.max function, I see the return type is a queue. I would like to understand why the return of max on an array of values have to be a queue, rather than a single value of the same data type of the original array.
Thanks in advance,
Madhu
In reply to mseyunni:
All of the array locator methods have the same prototype, and for some of them, it is possible to return an empty set.
In reply to dave_59:
Ok. My question was mainly why does the return type have to be a queue instead of a single value of that type?
In reply to mseyunni:
How would you suggest retuning an empty value?
In reply to dave_59:
Did you mean max function applied on a empty array? If it is empty array, then the compiler can throw an error. Otherwise, if there is a int q[3], with 3 values 4, 7 and 9. Then I would expect the max function returning a value of 9 as int.
The compilier does not know if the array is empty, you only know at runtime. As far as I know, some languages will throw a runtime error if you try a max/min on an empty array. Since SV does not have exceptions, I guess returning a queue was the most pragmatic approach (and keeps the function prototypes the same as Dave mentioned).
In reply to nzicha_acd:
Yes. I agree, the issue needs to be caught during run-time.