PreviousElement() after ResetList()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Olby
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Jan 12, 2009 10:33 am
Contact:

PreviousElement() after ResetList()

Post 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?
Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: PreviousElement() after ResetList()

Post 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
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
Demivec
Addict
Addict
Posts: 4261
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: PreviousElement() after ResetList()

Post 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().
Olby
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Jan 12, 2009 10:33 am
Contact:

Re: PreviousElement() after ResetList()

Post 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.
Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: PreviousElement() after ResetList()

Post by davido »

@Olby: +1 for consistency.
DE AA EB
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: PreviousElement() after ResetList()

Post by PMV »

ResetList() + While NextElement() is just a synonym for ForEach.
There is no for-loop to go backwards :shock: :mrgreen:
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. :wink:

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
Olby
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Jan 12, 2009 10:33 am
Contact:

Re: PreviousElement() after ResetList()

Post by Olby »

PMV wrote:ResetList() + While NextElement() is just a synonym for ForEach.
There is no for-loop to go backwards :shock: :mrgreen:
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. :wink:

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.
Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: PreviousElement() after ResetList()

Post 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. :lol:

I repeat myself ...
of course you can't jump into the backdoor if you
are standing at the frontdoor. :wink:
:)

MFG PMV
Olby
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Jan 12, 2009 10:33 am
Contact:

Re: PreviousElement() after ResetList()

Post 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. :lol:

I repeat myself ...
of course you can't jump into the backdoor if you
are standing at the frontdoor. :wink:
:)

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.
Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: PreviousElement() after ResetList()

Post by PMV »

Everything can get a different behavior if you change the definition.
Consistent is not a definition of someone misses a functionality. :lol:

It is up to Fred how PB works and i'm happy with everything
that is working as it is designed to be. :wink:
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? :mrgreen: Just kidding again. :oops: But sometimes
simpler is better.

MFG PMV
Olby
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Jan 12, 2009 10:33 am
Contact:

Re: PreviousElement() after ResetList()

Post 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. :lol:

It is up to Fred how PB works and i'm happy with everything
that is working as it is designed to be. :wink:
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? :mrgreen: Just kidding again. :oops: 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.
Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: PreviousElement() after ResetList()

Post by PMV »

I do that already ... but you like to get dizzy? I do :mrgreen:
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. :lol:
Post Reply