Page 1 of 1
PreviousElement() after ResetList()
Posted: Sun Jul 28, 2013 10:51 pm
by Olby
It would be useful if PreviousElement() after ResetList() would automatically jump to the last element in the list. Currently it does nothing on contrary to the NextElement(). Are there any associated issues with this?
Re: PreviousElement() after ResetList()
Posted: Sun Jul 28, 2013 10:56 pm
by STARGĂ…TE
PreviousElement() is not for ResetList()
Code: Select all
Define NewList Integer.i()
AddElement(Integer()) : Integer() = 1
AddElement(Integer()) : Integer() = 2
AddElement(Integer()) : Integer() = 3
; ResetList with NextElement
ResetList(Integer())
While NextElement(Integer())
Debug Integer()
Wend
; LastElement with PreviousElement()
If LastElement(Integer())
Repeat
Debug Integer()
Until Not PreviousElement(Integer())
EndIf
Re: PreviousElement() after ResetList()
Posted: Mon Jul 29, 2013 5:54 am
by Demivec
Olby wrote:It would be useful if PreviousElement() after ResetList() would automatically jump to the last element in the list. Currently it does nothing on contrary to the NextElement(). Are there any associated issues with this?
I agree that it would be useful if PreviousElement() functioned the same way as NextElement() does after a ResetList(). It would be more consistent. You wouldn't have to have different types of loop for traversing the list backwards because of the inconsistencies that currently exist between NextElement() and PreviousElement().
Re: PreviousElement() after ResetList()
Posted: Mon Jul 29, 2013 10:34 am
by Olby
Demivec wrote:Olby wrote:It would be useful if PreviousElement() after ResetList() would automatically jump to the last element in the list. Currently it does nothing on contrary to the NextElement(). Are there any associated issues with this?
I agree that it would be useful if PreviousElement() functioned the same way as NextElement() does after a ResetList(). It would be more consistent. You wouldn't have to have different types of loop for traversing the list backwards because of the inconsistencies that currently exist between NextElement() and PreviousElement().
This is the exact issue I'm facing at the moment. It is inconsistent with NextElement(). Stargate, your example is fine but it doubles the code whereas if PreviousElement() would work exactly like NextElement() we could just use a macro to replace the command but the loop would essentially stay the same.
Re: PreviousElement() after ResetList()
Posted: Mon Jul 29, 2013 1:33 pm
by davido
@Olby: +1 for consistency.
Re: PreviousElement() after ResetList()
Posted: Mon Jul 29, 2013 2:41 pm
by PMV
ResetList() + While NextElement() is just a synonym for ForEach.
There is no for-loop to go backwards
Just kidding. There is no issue as ResetList() puts the list-pointer
in front of the first element ... of course you can't jump into
the backdoor if you are standing at the frontdoor.
Just make a feature request if you wish to have a function like
ResetList() but instead of putting the list-pointer in front of the
first element, putting it after the last element to be able to use
PreviousElement() then.
MFG PMV
Re: PreviousElement() after ResetList()
Posted: Mon Jul 29, 2013 3:06 pm
by Olby
PMV wrote:ResetList() + While NextElement() is just a synonym for ForEach.
There is no for-loop to go backwards
Just kidding. There is no issue as ResetList() puts the list-pointer
in front of the first element ... of course you can't jump into
the backdoor if you are standing at the frontdoor.
Just make a feature request if you wish to have a function like
ResetList() but instead of putting the list-pointer in front of the
first element, putting it after the last element to be able to use
PreviousElement() then.
MFG PMV
I'm not saying there is an issue with ResetElement(). My point is that PreviousElement() is inconsistent with NextElement(). Why NextElement is able to jump into the list from -1 state while PreviousElement can not? You are right this should be moved to feature request.
Re: PreviousElement() after ResetList()
Posted: Mon Jul 29, 2013 3:31 pm
by PMV
You haven't read what i have written? ResetList() moves the
list-pointer in front of the first element! That is the behavior
as it is documented ... there is no inconsistent.
I repeat myself ...
of course you can't jump into the backdoor if you
are standing at the frontdoor.
MFG PMV
Re: PreviousElement() after ResetList()
Posted: Mon Jul 29, 2013 4:42 pm
by Olby
PMV wrote:You haven't read what i have written? ResetList() moves the
list-pointer in front of the first element! That is the behavior
as it is documented ... there is no inconsistent.
I repeat myself ...
of course you can't jump into the backdoor if you
are standing at the frontdoor.
MFG PMV
I guess we have different interpretation of what is possible and what is not. To me it would make sense if both commands would act appropriately.
Using your metaphor: If I'm at the front door and someone tells me to enter the house from the back, I would just turn around and enter from the back door. Simple!
Either make ResetList() with additional flag to move the pointer after the last element or simply make sure that if PreviousElement() is called and there is no current element jump straight to the last element of the list.
The help file for ResetElement() states "... this is very useful to allow you to process all the elements by using NextElement()". We should have similar alternative for PreviousElement(). PureBasic is a straight forward language and many things have been done to improve it and make it all around consistent. This should be one of them.
Re: PreviousElement() after ResetList()
Posted: Mon Jul 29, 2013 5:31 pm
by PMV
Everything can get a different behavior if you change the definition.
Consistent is not a definition of someone misses a functionality.
It is up to Fred how PB works and i'm happy with everything
that is working as it is designed to be.
And who knows, maybe we get a "BackEach", too. It just doesn't
will make it more consistent ... just more feature-rich.
Btw. if you are at the Backdoor and someone wants you to get through
the frontdoor, you just turn around again? How many loops can you handle
until you will break down?

Just kidding again.

But sometimes
simpler is better.
MFG PMV
Re: PreviousElement() after ResetList()
Posted: Mon Jul 29, 2013 8:33 pm
by Olby
PMV wrote:Everything can get a different behavior if you change the definition.
Consistent is not a definition of someone misses a functionality.
It is up to Fred how PB works and i'm happy with everything
that is working as it is designed to be.
And who knows, maybe we get a "BackEach", too. It just doesn't
will make it more consistent ... just more feature-rich.
Btw. if you are at the Backdoor and someone wants you to get through
the frontdoor, you just turn around again? How many loops can you handle
until you will break down?

Just kidding again.

But sometimes
simpler is better.
MFG PMV
I understand your point but in this case "simpler is better" does not apply as the additional code necessary to perform the same loop backwards makes it less simple

Not asking for BackEach as there are ways to do it without making things unnecessary complicated. Whereas a flag to move backwards from -1 state in PreviousElement() only makes it more consistent with NextElement().
Treat this as any other feature request and not a bash at PB. Every new feature or suggestion can make the language only better.
Re: PreviousElement() after ResetList()
Posted: Mon Jul 29, 2013 10:04 pm
by PMV
I do that already ... but you like to get dizzy? I do
It has nothing to do with consistent, thats all i'm talking about.
But ok, i stop it now. Enough rounds, to dizzy for more.
