1. Integer indexes?

Is this a bug or a feature?

   object X 
   sequence Y 
 
  Y = "abcdefghijklmnopqrstuvwxyz" 
 
   X = Y[2.11] 
 
   ? X 

This outputs the value 'b', however I made a typo because I wanted the output to be "bcdefghijk"

new topic     » topic index » view message » categorize

2. Re: Integer indexes?

Y[2.1] gets truncated to Y[2]

standard behavior since early Euphoria

be well
_tom

new topic     » goto parent     » topic index » view message » categorize

3. Re: Integer indexes?

Hi Tom.
I know that this is the behaviour, and that it's been around for ever, but should it be so?

I base this question on these

  • The documentation says the sequences take integer indexes.
  • Using a literal non-integer index is most likely a typo and not really intended by the coder.

Is anyone's code actually depending on this behaviour?

I'm not talking about variables used as index values that might not be an integer, only literals; that is hard-coded decimal indexes in the code.

new topic     » goto parent     » topic index » view message » categorize

4. Re: Integer indexes?

There might be a few explicit if s[2.99]!=s[2] then crash() in the unit tests, but otherwise I'd agree that should trigger a compilation error.

new topic     » goto parent     » topic index » view message » categorize

5. Re: Integer indexes?

petelomax said...

There might be a few explicit if s[2.99]!=s[2] then crash() in the unit tests, but otherwise I'd agree that should trigger a compilation error.

+1

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu