List behavior...

Hello, all--

I have the following snippet of code:
put (1,2,3,4) into myList
put the number of items in myList #=> 4
delete 4 from myList
put the number of items in myList #=> 4
What I don't quite get is the fact that even though I deleted the last item of the list, the list size is still 4 myList = (1,2,3,).Can someone explain what I am missing?

Thanks,
Allen

Comments

  • EggplantMattEggplantMatt ForumAdmin admin
    You need to do "remove item 4". "Delete 4" looks at each item in the list as a string and removes the specified string (in this case "4") from it if it exists. If you had a list like ("14", "24", "34", "44") and ran your command against it, you'd get ("1", "2", "3", ) as your final list.
  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    To explain it slightly differently: Currently you can't delete items from a list by value, only by their index (item number).

    So this will do what you want:
    delete item 4 of myList
    
    because it's explicitly referring to an item.

    When you don't specify items (or some other chunk type) by number, the delete command assumes you want to delete every occurrence of some text from a string, or (in your case) from a list of strings, so you get the behavior Matt described above.
Sign In or Register to comment.