ForEach for Strings
Re: ForEach for Strings
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
-
- Addict
- Posts: 1264
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
Re: ForEach for Strings
+1
I think this syntax would be cool:
where Delimiter is a bolded keyword, like Step in the standard For..Next loop.
I think this syntax would be cool:
Code: Select all
MyString$ = "1|2|3|4|5|..."
ForField temp$ in MyString$ Delimiter "|"
; do stuff with Temp$
NextField
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Re: ForEach for Strings
-1
I think it's not basic style
I think it's not basic style
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
- NicTheQuick
- Addict
- Posts: 1504
- Joined: Sun Jun 22, 2003 7:43 pm
- Location: Germany, Saarbrücken
- Contact:
Re: ForEach for Strings
I think it would be a more Basic approach when we do it in two steps.
- First allow iterating over a normal array:
Code: Select all
Dim myarray.i(10) ; Output all 11 entries ForEach myarray() Debug myarray() Next
- Then allow the implicit creation of arrays from functions:
Code: Select all
Dim myarray.s(0) ; Redim myarray to 6 elements and assign the values, separated by comma, to the elements of the array myarray() = SplitString("a,b,c,d,e,f", ",")
- Combine both features:
Code: Select all
ForEach SplitString("a,b,c,d,e,f", ",") As myarray() Debug myarray() Next
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Re: ForEach for Strings
Whenever syntax updates come up, you and some others always bring up this argument, and I'm trying to understand it. What exactly makes syntax classify as "BASIC-style" in your head? IMO sometimes things need ditched to move onto better things, even portions of BASIC (line numbers)? For me, I personally don't care about syntactical rules set by the designers of the first BASIC 50 years ago and would rather just be able to loop over my strings

I like this, but I think the reason you can't return arrays from procedures is because it could create a dangling reference/memory leak very easily.NicTheQuick wrote: Fri Jul 19, 2024 2:17 pm I think it would be a more Basic approach when we do it in two steps.Of course this is only an idea.
- First allow iterating over a normal array:
Code: Select all
Dim myarray.i(10) ; Output all 11 entries ForEach myarray() Debug myarray() Next
- Then allow the implicit creation of arrays from functions:
Code: Select all
Dim myarray.s(0) ; Redim myarray to 6 elements and assign the values, separated by comma, to the elements of the array myarray() = SplitString("a,b,c,d,e,f", ",")
- Combine both features:
Code: Select all
ForEach SplitString("a,b,c,d,e,f", ",") As myarray() Debug myarray() Next
-
- Addict
- Posts: 1264
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
Re: ForEach for Strings
So what?
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Re: ForEach for String
PureBasic does not look like 80's microcomputer Basic. Does also not look much like QuickBasic or Visual Basic. There is not one Basic for better or worse. So maybe meant does not look like PureBasic?
Anyway, lots of quality of life improvements for the programmer are possible. Probably to do with the "basic" asm compiler backend helping to keep it maintainable for one person. I hope after the welcomed bug fixing lately PB gets some actual syntax/language enhancements/modernization. But probably not, based on past feature requests. Just being realistic. In some cases even plain old boring c has nicer syntax (array declaration and initialization, structure return from function). Take a look at modern small procedural indy languages for ideas.
Anyway, lots of quality of life improvements for the programmer are possible. Probably to do with the "basic" asm compiler backend helping to keep it maintainable for one person. I hope after the welcomed bug fixing lately PB gets some actual syntax/language enhancements/modernization. But probably not, based on past feature requests. Just being realistic. In some cases even plain old boring c has nicer syntax (array declaration and initialization, structure return from function). Take a look at modern small procedural indy languages for ideas.
Re: ForEach for String
Agreed fully. The bug fixing spree was a welcome surprise so maybe Fred will surprise us, but sadly I'm not hopeful, PB's syntax is likely to stay what it is. I would very much like to see much expanded inline-C support at the very least though, so we can sort of use PB like BCX Basic and just put C code directly anywhere in our codeRinzwind wrote: Sat Jul 20, 2024 4:03 pm Anyway, lots of quality of life improvements for the programmer are possible. Probably to do with the "basic" asm compiler backend helping to keep it maintainable for one person. I hope after the welcomed bug fixing lately PB gets some actual syntax/language enhancements/modernization. But probably not, based on past feature requests. Just being realistic. In some cases even plain old boring c has nicer syntax (array declaration and initialization, structure return from function). Take a look at modern small procedural indy languages for ideas.

- Michael Vogel
- Addict
- Posts: 2797
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: ForEach for Strings
Just for fun - something completely different...
...yes, it's a simplified approach (single character delimiter) and nobody has asked for this here - anyhow this thread tends to collect heterogeneous opinions
...yes, it's a simplified approach (single character delimiter) and nobody has asked for this here - anyhow this thread tends to collect heterogeneous opinions

Code: Select all
Structure StringFieldMapType
ID.i
*pos.Character
string.s
delimiter.c
element.s
EndStructure
Global NewMap StringFieldMap.StringFieldMapType()
Procedure ResetStringField(string.s,delimiter.s)
With StringFieldMap(string)
\ID=0
\string=string
\pos=@\string
\delimiter=Asc(delimiter)
\element=""
EndWith
EndProcedure
Procedure NextStringField(string.s)
Protected *scan.Character
Protected cont
With StringFieldMap(string)
*scan=\pos
Repeat
Select *scan\c
Case 0
Break
Case \delimiter
cont=#True
Break
EndSelect
*scan+SizeOf(Character)
ForEver
If \pos=*scan
\element=""
ProcedureReturn #Null
Else
\element=PeekS(\pos,(*scan-\pos)/SizeOf(Character))
\pos=*scan+cont*SizeOf(Character)
\ID+1
ProcedureReturn #True
EndIf
EndWith
EndProcedure
Procedure.s StringFieldElement(string.s)
ProcedureReturn StringFieldMap(string)\element
EndProcedure
Procedure StringFieldId(string.s)
ProcedureReturn StringFieldMap(string)\ID
EndProcedure
s.s="1|2|3|4|five|sei|sieben|otto|neuf|deka"
ResetStringField(s,"|")
While NextStringField(s)
Debug Str(StringfieldId(s))+": "+StringFieldElement(s)
Wend
Debug "done"