jacdelad wrote: Wed Jul 17, 2024 5:17 am
No, I want an extended ForEach.
I think there is a common syntax used in many languages. An example of a custom syntax in PECMD that doesn't look like anything. It's like one person's own language.
By the way, if there are solutions using the existing syntax, then no one will come up with anything. But the function I proposed duplicates the memory by creating a list with the same contents. I tried to make pointers from the string and now the memory is not duplicated (probably).
jacdelad wrote: Wed Jul 17, 2024 5:17 am
No, I want an extended ForEach.
I think there is a common syntax used in many languages. An example of a custom syntax in PECMD that doesn't look like anything. It's like one person's own language.
By the way, if there are solutions using the existing syntax, then no one will come up with anything. But the function I proposed duplicates the memory by creating a list with the same contents. I tried to make pointers from the string and now the memory is not duplicated (probably).
Macro ForEachS(S,T)
For Count=1 To CountString(S,"|")+1
T=StringField(S,Count,"|")
EndMacro
MyString$="1|2|3|4|5|..."
ForEachS(MyString$,Temp$)
Debug Temp$
Next
Ok, so without wanting to sound rude: I know how to do this with existing code elements, sure. If it was something outstanding, I or someone else would have posted it in Tipps&Tricks. This section is for wishes, so, as I see it, things that are either not doable at the moment or things that change/enhance PureBasic internally.
As I wrote in my initial post, this is nothing completely new. I also know how to do this with existing functions. Your ideas are great as well. BUT, my request/question, was and is to enhance the command "ForEach". By your logic we don't need ForEach at all. Going through a list doesn't even need an auxiliar variable. But the command is here and I use it regularly. Is just want to use it with strings too, because I regularly go through string parts. I don't care how it would be done internally, I just want it to work with ForEach. That's why it is a request, not a trick or a question. Period.
tored wrote: Wed Jul 17, 2024 4:55 pm
Would be great if possible to hook into ForEach with an iterator, that way we can use ForEach with whatever collections we have.
Proof of concept
Edit: Fixed incorrect current() for IntArrayIterator