[Implemented] LinkedLists inside Structures

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
ZeHa
User
User
Posts: 38
Joined: Sun Apr 24, 2005 11:39 pm

Post by ZeHa »

If you're using NewList globally or in a function, it's generally nothing more than a simple pointer. You have a pointer to a list now, and you can use several functions like AddElement() and so on to work with that list.

If NewList would be possible inside a Structure, how would it be different? There would be no memory management madness, as there would be simply a pointer to store. Nothing too fancy, I think. If you're using C++ or Java and you're using a LinkedList inside a class, it's just a reference to the list, not the whole list elements saved inside the structure / class.
But as you say, there are many workarounds to do that, and some of these workarounds are really really elegant.
So then to implement that request would be a good way to complicate PB language unfoundedly, imo.
I don't think so. A list can be in global scope or in function scope. Why not also in structured scope? I don't see why this would make PB more complicated, in fact, it would only help to make it a better language. The workarounds are not elegant at all, since you always have to do weird stuff which is possible as a native thing in other languages.

You can also regard functions as an unnecessary feature, since we could use Gosub and Return as a workaround instead. And why do we have With and EndWith? We can also just do it the normal way. Why do we have Select and EndSelect? It can be done with several Ifs.
And why LinkedLists? We could write them on our own!

In my opinion, there are tons of cases where you would love to have some function like that. It's totally normal for other languages, and it's basically just a pointer, nothing special. It's just not possible to use it that way because of some syntactic stuff. If AddElement() could accept a pointer and if @listName() would return the address of the list (or the first element), it would be already possible.
Franky
Enthusiast
Enthusiast
Posts: 213
Joined: Sat Apr 26, 2003 2:58 pm

Post by Franky »

Ok, my 2 cents:

I think

Code: Select all

   Structure blabla
        wert.l ;This is a variable
        mydata[5];This is an array
        MyList.l() ;This is a Linkedlist
  Endstructure 
is a good idea.

I already wrote my own Macros to have this feature. But it would be handy to have it as normal PB-Stuff, because for the moment to get the Used Macros I have to call a selfmade Init-Macro for Each ListType (Type of the entries, I mean) I´m using.

I disagree to Hroudtwolfs idea indirectly.
This Dynamic stuff, he´s wishing is not bad, but I think PB should keep the LinkedlistSyntax for those funktions. Pointers are a little abstract for that. I mean, you don´t the, that it´s a Linkedlist.

It would be nice to have a syntax nearly like the one I created, but without the use of explaining the LLs Type. Something like "Virtual New List" would be nice in this case.

Could have been better at the beginning of PB, when Fred had used {} as Linkedlist-Breaks and Array-Breaks. Or as Procedure-Breaks, as one of the options. This way it had been clearly easy to see, if it´s a Linkedlist or a procedure. But it´s a little to late to change that, so no problem, it´s ok, that way, too.
Give Up everything but trying!
ZeHa
User
User
Posts: 38
Joined: Sun Apr 24, 2005 11:39 pm

Post by ZeHa »

I disagree because of two reasons ;)

1) NewList is an established PB keyword and it wouldn't be logical if some lists have to be made with NewList and some without.

2) There are quite a few OOP-precompilers around, which is a good thing, and if you declare lists only with "()", precompilers wouldn't have a chance to declare methods like that.

I know the second reason is not related to the official language, but I think the first reason should actually be strong enough ;) I know, arrays are also declared differently here (with "[]"), but that's also pretty inconsistent.
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

The syntax discussion is secondary. The capability is what counts. If the team decided to do this I am sure they would come up with a good syntax. :)

Memory management issues are big, but then so are a lot of other things in compilers. So let the developers have the headaches of baking it and let the users get and eat the cake. :D

A lot of people mention cross-platform as being PureBasic's big strength. This is a strength, but ..

.. the real strength is that PureBasic makes itself easy to use whilst still allowing advanced stuff to be done.

It possible for dabblers and dullards like me to get some reasonable stuff out. It is possible for others to do pretty advanced stuff that would give me a headache.

So adding features like this is a good thing for PureBasic to do. It adds value and marketability to the PureBasic product. It makes it attractive to others like me and certainly won't make it unattractive to others. After all, you can choose to not use something that exists but you cannot choose to use something that isn't there.

:mrgreen:
Dare2 cut down to size
JCV
Enthusiast
Enthusiast
Posts: 580
Joined: Fri Jun 30, 2006 4:30 pm
Location: Philippines

Post by JCV »

well said. :D

[Registered PB User since 2006]
[PureBasic 6.20][SpiderBasic 2.2]
[RP4 x64][Win 11 x64][Ubuntu x64]
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post by milan1612 »

Just spent 2 hours to bypass this limitation, that's really annoying :x. Fred or Freak,
would you please clarify wether or not you'll be adding this to Purebasic? Is it somehow
planned or at least on the todo list? I think it's at least one of the most requested
feature, if not the most. I really hate having to directly mess with memory
for such basic tasks - in a Basic language! Not ment to be rude but...:P
Windows 7 & PureBasic 4.4
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

This is definitely planned for the near future. I cannot tell you an exact version though, as implementing this is entirely up to Fred.
quidquid Latine dictum sit altum videtur
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post by milan1612 »

freak wrote:This is definitely planned for the near future. I cannot tell you an exact version though, as implementing this is entirely up to Fred.
Thanks for the clarification, that's great to hear! :)
Windows 7 & PureBasic 4.4
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Post by c4s »

freak wrote:This is definitely planned for the near future. I cannot tell you an exact version though, as implementing this is entirely up to Fred.
Soon we have a new release, right?
So I'm waiting (and hoping) :wink:

edit:
Oh I just realized that freaks and milans posts were made in 2009 (thought
2008) - Yeah.. so it's even more possible!
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Post by cas »

c4s wrote:So I'm waiting (and hoping) :wink:
Me too :)
Matt
Enthusiast
Enthusiast
Posts: 447
Joined: Sat May 21, 2005 1:08 am
Location: USA

Post by Matt »

I needed this in a project the other day, couldn't figure out how to do it in the help file. Went on the forums and found out it couldn't be done. :cry:

So I used a nasty method where two linked lists are joined together with an ID, like:

Code: Select all

Structure Categories
  name.s
  number.l
EndStructure

Structure Choices
  name.s
  pixelx.l
  pixely.l
  categoryNumber.l
  number.l
EndStructure
:oops:
Post Reply