AppendElement()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

AppendElement()

Post by IdeasVacuum »

AddElement() Adds a new empty element after the current element (or create the first element if none exist).

I propose AppendElement() to add an element at the end of the List (or create the first element if none exist).

This would eliminate testing the size of a List before applying LastElement(), which will crash if there are no elements.

Edit: AppendList() replaced by AppendElement(), better name as proposed by DontTalkToMe; I'm currently unable to reproduce the crash which led to this Wish. Not sure that's a good thing :?
Last edited by IdeasVacuum on Fri Jul 01, 2016 1:17 am, edited 2 times in total.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: AppendList()

Post by Thunder93 »

There is no crash with PB 5.42 LTS

Code: Select all

NewList Numbers.b()

LastElement(Numbers())

If it crashes it would be a PB bug. You suppose to be-able to have a return value on LastElement() to know if it has an element or none.

PB Help: Return Value "... and zero if there if there are no elements in the list." ... not sure why PB help repeats if there :P
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: AppendList()

Post by Little John »

Thunder93 wrote:There is no crash with PB 5.42 LTS

Code: Select all

NewList Numbers.b()

LastElement(Numbers())

If it crashes it would be a PB bug.
I agree.

Also no crash when running the above code snippet here, tested with PB 5.42 LTS x86 and x64 on Windows 10.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: AppendList()

Post by IdeasVacuum »

...strange. I'm seeing a crash with a structured list, maybe that makes a difference though I don't see why it should.
AppendList() would nonetheless be usefull.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: AppendList()

Post by Thunder93 »

It doesn't appear to make a difference for my test.

Code: Select all

Structure BasicStructure 
    Field1.b
    Field2.w
    Field3.l
EndStructure

NewList TestList.BasicStructure()

Debug LastElement(TestList())
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: AppendList()

Post by Little John »

IdeasVacuum wrote:...strange. I'm seeing a crash with a structured list, maybe that makes a difference though I don't see why it should.
Maybe you can post a bug report with a short code snippet that demonstrates the issue?
IdeasVacuum wrote:AppendList() would nonetheless be usefull.
I agree.
DontTalkToMe
Enthusiast
Enthusiast
Posts: 334
Joined: Mon Feb 04, 2013 5:28 pm

Re: AppendList()

Post by DontTalkToMe »

... as long as it is called AppendElement() and not AppendList() since we have AddElement(), InsertElement() and what's being appended is not a list. :)
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: AppendList()

Post by IdeasVacuum »

....good point (element) :D
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply