Re: ? 1={}, is there really any other interpretation?
- Posted by Pete Lomax <petelomax at blueyon?er.c?.uk> Jul 19, 2007
- 627 views
Andy Serpa wrote: > > Some ways I frequently use sequence ops. <snip> > }}} <eucode> > global function filter(sequence mask, sequence s) > global function split(sequence mask, sequence s) > </eucode> {{{ I see, thank you for the examples. My detailed analysis follows. Please read through and reserve comments to my summary, thanks. Now, clearly as you are one of the most creative users of sequence ops I know, and I am not expecting you to be "happy" with this, I just wanted to say that if the proposed new scheme is implemented, you'd get type check error, mask is 1 (or 0), and know immediately what line needed to be changed:
s = filter(s>5,s)
would need to be replaced with either:
s = filter(sq_gt(s,5),s)
or:
s = filter(s@>5,s)
To complete the picture (dropping any @-style from now on, I trust you can figure those out for yourself, and it would be up to you to argue for new @-ops it seems, plus what follows may well sound like and in fact my whole point is that it is indeed your worst-case-scenario), I shall continue with every example you gave:
records_from_80209 = filter(zip_code = 80209,address_records)
replaced with:
records_from_80209 = filter(sq_eq(zip_code,80209),address_records)
and
s = split(s>5,s)
would need to become:
s = split(sq_gt(s,5),s)
and
s = filter(s < 0 or s > 10,s)
with
s = filter(sq_or(sq_lt(s,0),sq_gt(s,10)),s)
Admittedly uglier but then again you failed to convince me that you would ever actually need such code. Also,
indexes_of_elements_greater_than_5 = ilist(length(s)) * (s > 5)
would fail, provided that indexes_of_elements_greater_than_5 is declared as a sequence, as it should be, and would need to become:
indexes_of_elements_greater_than_5 = sq_mul(ilist(length(s)),sq_gt(s,5))
and
if sum(s > 5) > 10 then...
would need to become:
if sum(sq_gt(s,5)) > 10 then...
and lastly,
s/100
sq_div(s,100)
The closing snippet:
s = ((s>=5)*(s*10)) + ((s<5)*(s*100))
smacked of clutching at straws to me and seems way better as:
for i=1 to length(s) do si=s[i] if si>=5 then s[i]=si*10 else -- or elsif si<5 s[i]=si*100 end if end for
Much faster, and far easier to follow, and/or amend, in fact I would indeed go as far as to claim more typing but much easier to write. SUMMARY: As noted above, in no way do I expect you to be chomping at the bit for a chance to apply such changes (as if), but the above is basically what the proposal would [probably] mean you'd have to do. I always knew there would be a cost to bear, and it seems you would bear the biggest burden. But I have to say it seems bearable if you are somehow convinced of a greater good. Again I thank you for the examples posted and am personally very pleased to note that they would all fail "loudly" rather than in some obscure and difficult to track down way, under the proposal. I do accept that rarely executed parts of the code could prove harder to find. Regards, Pete PS Naturally, I am assuming the above changes could be made to impose an undetectable runtime performance hit, not that such appears to worry you.