Re: [tutorial] Basic Sequence Operations
- Posted by archeopteryx_08 Jan 27, 2019
- 1330 views
Speaking of basic sequence operations, on page 43 of the euphoria (4.1) pdf there is this code:
sequence s = {1,2,3} for i=0 to length(s)+1 do ? insert(si, 99, i ) end for -- the output is -- {99,1,2,3} -- {99,1,2,3} -- same as prepend(s,99) -- {1,99,2,3} -- {1,2,99,3} -- {1,2,3,99} -- same as append(s,99)
I understand what it's doing, but i can't help feel uncomfortable that insert() works when i=0, and that it gives the same value as when i=1. At (my) first sight, it appears visually to suggest that the inserted object (ie 99) should occupy s[0] (i know it doesn't!), then s[1] ... to s[4] - almost like a visual illusion. It isn't a big thing, but maybe insert() was designed to work this way; maybe it works well in real code ?
_Arch