AddElement(List()) = "Value"

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

AddElement(List()) = "Value"

Post by Joakim Christiansen »

Able to write:

Code: Select all

AddElement(List()) = "Value"
Instead of:

Code: Select all

AddElement(List())
List() = "Value"
Would be handy for LinkedLists without a structure, but nothing important it's just nice syntax.
I like logic, hence I dislike humans but love computers.
technicorn
Enthusiast
Enthusiast
Posts: 105
Joined: Wed Jan 18, 2006 7:40 pm
Location: Hamburg

Post by technicorn »

Try this:

Code: Select all

Macro AddElementAssign(list)
  AddElement(list) : list 
EndMacro

NewList l1.l()
NewList s1.s()

AddElementAssign(l1()) = 123
Debug l1()

AddElementAssign(s1()) = "Hello1"
Debug s1()

If AddElementAssign(s1()) = "Hello2"
Else
  Debug "Out of memory"
EndIf
Debug s1()
I don't think this will be implemented, AddElement() is a function that
returns a pointer, so the compiler had to deside for assignment or pointer returning,
that would make compiling more complicated than necessary.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

additionally, a LinkedList often is used for structured elements.
it is impossible to assign a complex structure with "="
oh... and have a nice day.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

I'd be tempted to request something like this:

Code: Select all

Structure x
  a.l
  b.l
EndStructure

z.x
z = 1,2

 :)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

blueznl: It's kinda nice.
I like logic, hence I dislike humans but love computers.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Kaeru Gaman wrote:additionally, a LinkedList often is used for structured elements.
it is impossible to assign a complex structure with "="
AddElement(StructuredList())\Member = Value
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

this is one element of a complex structure, not the structure itself... :roll:
oh... and have a nice day.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

So what? It's not needed to set the entire structure. You can't do that even without the AddElement().
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

Kaeru Gaman wrote:it is impossible to assign a complex structure with "="
oh... and have a nice day.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

So what?
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post by Demivec »

You could use curly braces as delimeters for a structured set.

Code: Select all

Structure x
a.l
b.l
c.s
d.d
EndStructure

z.x
z = {1,2,"three",4.5}
z = {,,"three"}  ;to set just the third element
;or
NewList y.x()
AddElementAssign(y(),{,z\a,"three"})
Curly's are a bit harder to see though and this would get crazier with arrays and unions and such.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

Trond wrote:So what? It's not needed to set the entire structure. You can't do that even without the AddElement().
that's what I said more than once.
an AddElementX() = bla is useless, since you can never use it for structured elements.
and I would say, 99% of LinkedLists are structured.
in fact, I see no use in a List without a structure.
oh... and have a nice day.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Then Variable = Value is useless also, since you can't use it for structures?
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

Trond wrote:Then Variable = Value is useless also, since you can't use it for structures?
*sigh* what is you problem?

1. a complex structure cannot be filled with "="
2. the main use of LinkedLists is to use structured Lists.
=> an AddElement() = value is almost always useless.

that is my point, nothing less, nothing more.
oh... and have a nice day.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Why is it almost useless? It saves 1 line. Which is exactly the same number of lines that's saved for unstructured lists. So it's just as useful. It will also save more lines in case you do not need to initialize all the structure members.
Post Reply