ForEach listName() Where condition - also ordering lists

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

ForEach listName() Where condition - also ordering lists

Post by Dare2 »

Would it be possible to add an optional WHERE condition or similar to ForEach?

Code: Select all

ForEach listname() WHERE listname()\fldname = "YES"
  .. process
next

; translating internally to something like:

ForEach listname()
  if listname()\fldname="YES"
    .. process
  endif
next
Effectively the WHERE is treated as a following IF and there is an endif applied just before the next.

Hopefully this would add no extra code to the final executable (the user currently has to do some testing inside the loop, which would no longer be needed) - and might in fact make this slightly smaller or faster through compilation optimisations.

[ASIDE]

Ordered lists would also be nice - I order lists using a Binary Search but it can get slow on large lists, with several SelectElement(LinkedList(), Position) and associated tests and postion adjustments happening before the item is included in the list.

But an optional ordering/sorting ability, something like:

Code: Select all

NewList listname.listDef() [ ASCENDING | DESCENDING [ IGNORECASE ] ON fldName ]
would be great! - and would surely be fast.

[/ASIDE]