Post Reply 
Adding an entry to a vector or list
09-27-2023, 12:53 PM
Post: #10
RE: Adding an entry to a vector or list
(09-25-2023 11:22 PM)Albert Chan Wrote:  
(09-24-2023 04:13 PM)Tyann Wrote:  You can also use list(-1):=expr, in which case expr will be added to the top of the list.

Is negative index HOME table insertion documented anywhere?

This is very confusing, positive index for table assignment, non-positive index for table insertion.
Table lost its nice boundary checks, with possibly nasty bug, especially if index were computed.

Also, if index 0 is for end-of-list, -1 should really be one before, not head-of-list. It made no sense.

I do not like this either. Using a negative number to indicate insertion rather than replacement is confusing and non-standard. In many languages, particularly Python (another Prime language option), a negative index indicates offset from the end of the list rather than the beginning. I can't see a reason for this odd notation as opposed to the more standard insert.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Adding an entry to a vector or list - John Keith - 09-27-2023 12:53 PM



User(s) browsing this thread: 6 Guest(s)