Page 1 of 2

AddElement(List()) = "Value"

Posted: Sun Aug 19, 2007 8:08 pm
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.

Posted: Sun Aug 19, 2007 10:58 pm
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.

Posted: Sun Aug 19, 2007 11:24 pm
by Kaeru Gaman
additionally, a LinkedList often is used for structured elements.
it is impossible to assign a complex structure with "="

Posted: Tue Aug 21, 2007 12:32 pm
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

 :)

Posted: Tue Aug 21, 2007 8:56 pm
by Joakim Christiansen
blueznl: It's kinda nice.

Posted: Wed Aug 22, 2007 10:23 am
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

Posted: Wed Aug 22, 2007 12:21 pm
by Kaeru Gaman
this is one element of a complex structure, not the structure itself... :roll:

Posted: Wed Aug 22, 2007 3:55 pm
by Trond
So what? It's not needed to set the entire structure. You can't do that even without the AddElement().

Posted: Wed Aug 22, 2007 4:31 pm
by Kaeru Gaman
Kaeru Gaman wrote:it is impossible to assign a complex structure with "="

Posted: Wed Aug 22, 2007 5:46 pm
by Trond
So what?

Posted: Wed Aug 22, 2007 6:16 pm
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.

Posted: Wed Aug 22, 2007 7:30 pm
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.

Posted: Wed Aug 22, 2007 8:31 pm
by Trond
Then Variable = Value is useless also, since you can't use it for structures?

Posted: Wed Aug 22, 2007 8:38 pm
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.

Posted: Wed Aug 22, 2007 8:54 pm
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.