How do lists work?
Monkey Forums/Monkey Programming/How do lists work?| 
 | ||
| Hello, How do lists work in Monkey? I see lists for Strings, and Int, but can we have lists of Object Instance references? | 
| 
 | ||
| Dealing with objects and the new generics feature mean the syntax has changed quite a bit. Here's an example 
Class Dude           'declare a new type
  Field name$
  Method New(_name$)  'define the constructor function. It can take arguments now!
    name = _name
  End
End
Local dudes:List<Dude>           'create a new list, which takes Dude objects
dudes.AddLast (New Dude("Jim"))  'add a new Dude to the list.
For Local dude:= EachIn dudes    'You must put Local/Global before variable declarations now, but you can declare type implicitly with the := operator
  Print dude.name
Next
 | 
| 
 | ||
| anyone knows a way to get the values of the list from bottom to top? something like: for local i = list.Count()-1 to 0 step -1 list.elementAt(i) end | 
| 
 | ||
| You could make a temp List and copy the items into it using AddFirst(). Or use a Stack. | 
| 
 | ||
| It would be nice to have a List.Reverse() and List.Reversed() like in BlitzMax |