Page 1 of 1
With/EndWith integrated to ForEach/Next
Posted: Tue Jan 16, 2007 8:51 pm
by Flype
A small snippet is better than a long explanation. All is in the title and the snippet :
I'm not sure if it's a good idea - maybe yes maybe no - just discuss about it.
Code: Select all
Structure PRODUCT
id.s
name.s
price.s
desc.s
EndStructure
Global NewList product.PRODUCT()
ForEach product()
With product()
Debug "id = " + \id
Debug "name = " + \name
Debug "price = " + \price
Debug "desc = " + \desc
Debug ""
EndWith
Next
ForEach product()
Debug "id = " + \id ; <--------- Syntax Error.
Debug "name = " + \name
Debug "price = " + \price
Debug "desc = " + \desc
Debug ""
Next
Posted: Tue Jan 16, 2007 8:54 pm
by Trond
I once suggested this and people thought it was dreadful. But I think it's a good idea.
Posted: Tue Jan 16, 2007 8:57 pm
by Kaeru Gaman
hm... *shrug*
could be useful, but the leading backslash looks strange to me..
think i won't use it. copy/paste of the listname is sufficent ....
Posted: Tue Jan 16, 2007 9:22 pm
by AND51
There is something similar in CGI - very useful.
$_ is the abbreviation for the currently used array in CGI/Perl.
I would appreciate this request, if there are no conflicts with other commands and if I still can access another linked list in that foreach/next loop.
Peaople like Kaeru Gaman, who don't like this, can still use myList()\id, etc within the foreach/next.
Posted: Tue Jan 16, 2007 9:53 pm
by remi_meier
No way!
Code: Select all
NewList ll.Long()
NewList ll2.Long()
ForEach ll()
ForEach ll2()
\l = 4
Next
Next
Posted: Tue Jan 16, 2007 10:50 pm
by Flype
Hi remi_meyer.
No Way ! Hmmmm, Why ?
Code: Select all
NewList ll.Long()
NewList ll2.Long()
ForEach ll()
\l = 1 ; same as ll()\l
ForEach ll2()
\l = 4 ; same as ll2()\l
Next
Next
ForEach ll()
ForEach ll2()
ll()\l = 4 ; if you need to use ll() in ll2()
Next
Next
Posted: Tue Jan 16, 2007 10:53 pm
by remi_meier
That's just a mess...
Do you see the reason, why With-EndWith is not nestable?
Posted: Tue Jan 16, 2007 11:25 pm
by Flype
Yes, i can easily imagine the mess for the pre-processor and for the pre-pre-processor (Fred/Freak).
I'm just discussing...
Posted: Tue Jan 16, 2007 11:33 pm
by Kaeru Gaman
well... let me add the mess for the readability of your code...

Posted: Wed Jan 17, 2007 4:48 am
by nco2k
i think its a bad request.
if you want to use it that much, then simply write:
Code: Select all
ForEach List()
With List()
\Element = 0
EndWith
Next
i totally agree with remi.
c ya,
nco2k
Posted: Wed Jan 17, 2007 6:25 am
by Hroudtwolf
Code: Select all
Macro ForEachWith (_LIST_)
ForEach _LIST_ : With _LIST_
EndMacro
Macro NextWith
EndWith : Next
EndMacro
NewList test ()
AddElement (test ()):test()=1
AddElement (test ()):test()=2
AddElement (test ()):test()=3
AddElement (test ()):test()=4
ForEachWith (test ())
Debug test ()
NextWith
Posted: Wed Jan 17, 2007 10:27 am
by SCRJ
No, in version 4.02, you can't use "with" in macros.
Have a look on this topic
http://www.purebasic.fr/english/viewtopic.php?t=25273
Posted: Mon Apr 16, 2007 6:33 pm
by Joakim Christiansen
I agree that a With integrated in the ForEach loop would be nice.
Something like this:
Code: Select all
ForEach With Apples()
;bla bla
Next
The compiler should then see that With is used in the ForEach loop and end it at the Next command. I think this is the best way to do it? Fred?

Posted: Tue Apr 17, 2007 12:25 am
by jear
What is intended to be the higher abstraction level: ForEach or With?
Code: Select all
Structure Leute
Name.s
Vorname.s
Strasse.s
PLZ.s
Ort.s
EndStructure
NewList Leute.Leute()
With Leute()
ForEach
\PLZ = "26160"
Next
EndWith