chained compares was a real PITA
"Mark Hahn" <[email protected]> Fri, 9 Apr 2004 02:14:33 -0700
| Newsgroups | gmane.comp.lang.prothon.devel |
|---|---|
| Message-ID | <000501c41e13$12e92e20$d701a8c0@MarkVaio> |
It took me 2 and a half days to get chained compares (a < b < c) in and working. I ended up doing it three different ways before I got it right. It now evaluates with the implied ANDs, evaluates each term only once, and short-circuits properly. I ended up utilizing prototypes to their best advantage. I made an object, representing a compare result, that delegated everything, data and methods, to the real compare result, to fool everything into thinking it was that object, but made one change to it so that it behaved differently when used in the next compare in the chain. For the first time the prototype-based stuff was a real advantage.