Re: justifying compare
David Cuny writes:
> Can you get rid of the 'compare' statement from Euphoria? If not, why?
> Having used Euphoria for some time now, I've gotten used to *most*
> of it's quirks, and even grown to love them.
> The 'compare' statement is not one of them. If there is an error in
> my code, odds are that I've written:
> if compare( foo, bar ) then
> instead of:
> if compare( foo, bar ) = 0 then
I've done the same thing myself on occasion.
I've also done it in C with the strcmp() function which also
returns -1, 0 or +1.
How would you like an equal(a, b) function that returned
1 (true) when arbitrary objects a and b are equal, and 0 (false)
otherwise? e.g.
if equal(foo, bar) then
It would be a new built-in function like compare()
and would take the same amount of time to execute (it would
execute essentially the same code internally). By the way,
things are currently optimized so the extra = 0 after compare()
costs nothing.
For the time being, Carl R. White writes:
> global function equal(object a, object b)
> return compare({a},{b})=0
> end function
There's no need for the braces. Why not simply...
global function equal(object a, object b)
return compare(a,b)=0
end function
compare() will compare *any* object against any other.
with all atoms considered "less than" all sequences.
equal() would compare any object against any other for equality.
The redundancy is probably justified given the frequency with
which equal() would be used, and the error-prone nature
of compare(a,b) = 0.
Regards,
Rob Craig
Rapid Deployment Software
http://members.aol.com/FilesEu/
|
Not Categorized, Please Help
|
|