Re: Python has Traps; Does Euphoria have Programming Traps?

new topic     » goto parent     » topic index » view thread      » older message » newer message
jaygade said...

Not so much a "trap", as it produces an immediate failure, but rather that it's non-obvious enough to be pointed out. It will affect how certain algorithms are expressed in Euphoria code:

Comparison of sequences
Using comparison operators on sequences does not work the way most people expect. If you use a comparison operator between an atom and a sequence, or between two sequences of the same length, then you get a sequence of ones or zeros back as the result of the comparison. If you use a comparison operator between two sequences of different lengths then you get an error.

If you want to compare two sequences and get a true/false value then you must use equal(); if you want to get a relative value of less, equal, or greater than you must use compare(). If you want to compare an atom to a sequence then you must iterate over the sequence because all atoms are less than all sequences.

Since strings are sequences of integers, this holds true for strings as well as for generic sequences.

This is documented in the manual, but it is still a very important point.

I've gotten burned by this before too. More than once, even.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu