September 25, 2020, 02:03:05 AM

Author Topic: Disappearing value in TList  (Read 272 times)

Offline Henri

  • Sr. Member
  • ****
  • Posts: 256
Disappearing value in TList
« on: June 01, 2020, 09:24:04 PM »
Hi,

I'm converting my app from legacy bmax to ng and found this little thing.

You add three ingredients to your list, but when you go shopping, one is missing:

Code: BlitzMax
  1. SuperStrict
  2.  
  3. Local list:TList = New TList
  4. list.addlast("one")
  5. list.addlast("")
  6. list.addlast("three")
  7.  
  8. Print "List has " + list.Count() + " objects."
  9.  
  10. For Local s:String = EachIn List
  11.      Print s
  12. Next
  13.  


I was expecting to find all three or did I miss something?

-Henri
- Got 01100011 problems, but the bit ain't 00000001

Offline fightlessbirds

  • Jr. Member
  • **
  • Posts: 10
Re: Disappearing value in TList
« Reply #1 on: June 01, 2020, 09:29:03 PM »
It looks like the For-Each loop ignores empty strings. By changing "" to " " I was able to print all three elements.

Offline Derron

  • Hero Member
  • *****
  • Posts: 3178
Re: Disappearing value in TList
« Reply #2 on: June 01, 2020, 10:23:26 PM »
Extended your code ...

Code: BlitzMax
  1. SuperStrict
  2. Framework Brl.StandardIO
  3. Import Brl.LinkedList
  4. Import Brl.ObjectList
  5.  
  6.  
  7. Local list:TList = New TList
  8. list.addlast("one")
  9. list.addlast("")
  10. list.addlast("three")
  11.  
  12. print "TList + eachin: " + list.Count() + " objects."
  13. For Local s:String = EachIn List
  14.      Print "  eachin: " + s
  15. Next
  16.  
  17. print "TLink traversal:"
  18. local f:TLink = list.FirstLink()
  19. While f
  20.         print "  tlink: " + String(f.Value())
  21.         f = f.NextLink()
  22. Wend
  23.  
  24. Print "list.ToArray() + eachin: " + list.ToArray().length + " objects."
  25. For Local s:String = EachIn list.ToArray()
  26.      Print "  listarray: " + s
  27. Next
  28.  
  29.  
  30. Print "Array + eachin:"
  31. For Local s:String = EachIn ["one", "", "three"]
  32.      Print "  array: " + s
  33. Next
  34.  
  35.  
  36. local oList:TObjectList = new TObjectList()
  37. oList.AddLast("one")
  38. oList.AddLast("")
  39. oList.AddLast("three")
  40.  
  41. print "TObjectList + eachin: " + oList.Count() + " objects."
  42. For Local s:String = EachIn oList
  43.      Print "  eachin: " + s
  44. Next
  45.  

Directly using an array - works.
Converting the TList to an array - fails (but the array contains 3 elements)
Iterating over the TList with the TListEnum - fails
Iterating over the TLinks of the TList by traversing - works


Edit: added (failing) part for TObjectList - and raised an issue at github for it.
https://github.com/bmx-ng/brl.mod/issues/176

bye
Ron

Offline Henri

  • Sr. Member
  • ****
  • Posts: 256
Re: Disappearing value in TList
« Reply #3 on: June 01, 2020, 10:46:59 PM »
Excellent investigative work there :-)

-Henri
- Got 01100011 problems, but the bit ain't 00000001

Offline Derron

  • Hero Member
  • *****
  • Posts: 3178
Re: Disappearing value in TList
« Reply #4 on: June 10, 2020, 06:33:25 PM »
Brucey uploaded a fix to BCC ... requires a BCC rebuild of course.


bye
Ron

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal