Re: = vs := and = vs ==
- Posted by petelomax May 11, 2014
- 1895 views
If I was designing a Euphoria-like language, here's how I would handle operators:
Mismatched sequence size is a no op for elements of the longer sequence [even for - and /]. {} op object is no op. Returns object unchanged.
Interesting idea. Not that I have any compelling reason to make such changes, given the following function implements the current behaviour,
function sq_div(object a, object b) if atom(a) then if atom(b) then return a/b end if for i=1 to length(b) do b[i] = sq_div(a,b[i]) end for return b elsif atom(b) then for i=1 to length(a) do a[i] = sq_div(a[i],b) end for return a end if if length(a)!=length(b) then fatal(a,b) end if for i=1 to length(a) do a[i] = sq_div(a[i],b[i]) end for return a end function
then this implements that suggestion
function xq_div(object a, object b) if atom(a) then if atom(b) then return a/b end if for i=1 to length(b) do b[i] = xq_div(a,b[i]) end for return b elsif atom(b) then for i=1 to length(a) do a[i] = xq_div(a[i],b) end for return a end if -- if length(a)!=length(b) then fatal(a,b) end if if length(a)<length(b) then for i=1 to length(a) do b[i] = xq_div(a[i],b[i]) end for return b end if for i=1 to length(b) do a[i] = xq_div(a[i],b[i]) end for return a end function
Not exactly difficult, at least in hll, though there are quite a few of them, and like I said I'm not convinced it is necessarily an improvement.
{} is false. Any non-empty sequence is true.
Oh, I have heard that one before
I concluded this is a knee-jerk reaction to the dreaded "true/false condition must be an ATOM", which used to plague me back in the days when I used RDS Eu.
Since moving full-time to Phix and removing implicit sequence ops, this happens, I kid you not, less than once a year.
Besides, I simply just don't buy that expressions such as "{1,2,3} and {4,5,6}" have any meaningful true/false answer, and for my money "programming error" wins hands down.
For Euphoria's current comparison behavior, I would use builtins.
I have no clear idea what you really mean by that. If you are thinking of some mythical performance-related issue, I have found that it is almost always faster to use a non-sequence-op method, and in fact hll code such as that above can be aggressively pass-by-reference-optimized [although I should admit to recently breaking that handling in Phix] and therefore (at least for quite long/nested sequences) massively outperform the equivalent low-level code.
Pete