Re: 2.6 feature request: foreach (off topic)

new topic     » topic index » view thread      » older message » newer message

Vincent wrote:
> ; PureBasic
> 
> x.b  ; declare variable: 'x' as type "byte"
> adder.b  ; declare variable: 'adder' as type "byte"
> 
> NewList ListItem.b()  ; byte
> 
> Repeat
>     AddElement(ListItem()) : ListItem() = 1
> Until CountList(ListItem()) = 10  ; lets make 10 elements
> 
> adder = ListItem()
> x = 5  ; lets select element #5
> 
> SelectElement(ListItem(), x+2) ; add 2 because an index of 0 is possible
> ListItem() = adder + 7
> 
> ; show that it worked in the debugger window and console window.
> OpenConsole()
> ConsoleTitle("Example")
> Print("{")
> 
> ForEach ListItem()
>     Print(Str(ListItem()) + ",")
>     Debug ListItem()
> Next
> 
> Print("}")
> Input()
> CloseConsole()
> End  ; terminate program
> 
> --------------------------------------------
> console output: {1,1,1,1,1,1,1,8,1,1,}
> debugger output: 1 1 1 1 1 1 1 8 1 1

PureBASIC linked lists vs. Euphoria sequences:

Did they tell you that each element of a PureBASIC linked list
has a 4-byte pointer to "next", a 4-byte pointer to "previous"
and probably at least 8 bytes of overhead for malloc? 

Did they tell you that to "SelectElement" item number one million, 
they might have to internally follow a chain of one million pointers 
in memory? i.e. after converting from sequences to PureBASIC lists, 
you might find your program running a *million* times slower,
while each integer uses 20 bytes of space in memory?

And there's no error checking, so if you ask
for an invalid element, your program will likely crash.

They of course have (inflexible) arrays:

  "Once an array is 'sized' it can be resized 
   but its content will be deleted"
  (ouch!)

  "Arrays are always globally accessable in PureBasic."
  (no way to restrict access by scope!)

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu