Page 2 of 2
Re: multiple assignment
Posted: Sun May 03, 2020 3:20 pm
by skywalk
Yes, I was downvoting multiple RETURN values.
Multiple assignment is barely OK, but I would never use it since I use automated parsing tools.
And I rarely use colons.
This is annoying, lazy and crazy:
Protected x$, y.d, z.i = "123", 123.00, 123
Re: multiple assignment
Posted: Sun May 03, 2020 3:28 pm
by FlatEarth
The Goto command is nonsense in my opinion, I never use it. But it exists in pb.
Re: multiple assignment
Posted: Sun May 03, 2020 3:36 pm
by Little John
kenmo wrote:3. It would reduce reliability?
It would have zero change on the compiled executable.
The team has implemented features 100x more complex than this.
I think they can handle parsing this:
I agree that multiple assignment wouldn't reduce reliability.
But it can reduce
readability, like it's shown in your example above.
The way we are writing the same stuff currently is considerably better readable:
kenmo wrote:PS. I think we complicated this thread by bringing up multiple returns from procedures.
THAT is a much bigger change, a fundamental change to the language.
Well, the ability of procedures to return multiple values would be the main advantage of all this.
The possibility of multiple assignment without the possibility of procedures returning multiple values is pretty pointless.
Re: multiple assignment
Posted: Sun May 03, 2020 7:43 pm
by kenmo
Protected x$, y.d, z.i = "123", 123.00, 123
Yes, that is ugly. But you're choosing to make it that
It makes the most sense for pairs or triples of the same type, such as screen dimensions, xyz coordinates, etc.
It's very common for coordinates and vectors to be written as (a, b, c, ...) in mathematics, engineering, pseudocode, math-focused languages... it's not unreadable or confusing if it's just a few values of the same type.
Define.d x=0.0, y=1.0, z=2.0
That is pretty close to what is being requested here. Which is why (I like this feature request but) it's not urgent at all.
At least we don't have to write the word "Define" 3 times
Well, the ability of procedures to return multiple values would be the main advantage of all this.
The possibility of multiple assignment without the possibility of procedures returning multiple values is pretty pointless.
I don't think so. These are two separate features. One a minor syntax shorthand. The other a big change to how procedures work.
The language could implement one, the other, neither, or both.
Code: Select all
width, height = 640, 480 ; just simple shorthand, compiles the same as width=640 : height = 480
width, height = CalcSize() ; (these vars) = (unpack the multi-value result of a multi-return procedure)
Re: multiple assignment
Posted: Sun May 03, 2020 8:06 pm
by Danilo
kenmo wrote:It makes the most sense for pairs or triples of the same type, such as screen dimensions, xyz coordinates, etc.
It's very common for coordinates and vectors to be written as (a, b, c, ...) in mathematics, engineering, pseudocode, math-focused languages... it's not unreadable or confusing if it's just a few values of the same type.
I'm learning the Rust programming language recently (started 2 month ago),
and what you are talking about here is called
Tuple's there:
Code: Select all
fn main() {
let tup = (500, 6.4, 1); // create tuple
let (x, y, z) = tup; // destructuring the tuple
println!("The value of y is: {}", y);
}
Tuple's are represented using values/types between '(' and ')'.
It can be seen like an anonymous structure. Because there are no
struct member names, you can access the elements inside tup via tup.0, tup.1, tup.2, etc..
Of course Tuple's can be returned from functions as well, it is a real compound data type.
For some quick informations and to get an idea:
- Video:
Rust Tutorial by Doug Milford => Rust Tuples
- Book:
Rust By Example => Tuples
- Book:
The Rust Programming Language => data types => The Tuple Type
Re: multiple assignment
Posted: Sun May 03, 2020 8:43 pm
by kenmo
Yep, I know tuples mostly from Python.
But like you said, it's a compound data type, which you can do all sorts of nice things with, but it's more complicated than the original feature request here (shorter initial assignments).
Re: multiple assignment
Posted: Sun May 03, 2020 9:24 pm
by Little John
kenmo wrote:Well, the ability of procedures to return multiple values would be the main advantage of all this.
The possibility of multiple assignment without the possibility of procedures returning multiple values is pretty pointless.
I don't think so. These are two separate features. One a minor syntax shorthand. The other a big change to how procedures work.
The language could implement one, the other, neither, or both.
These two features, as proposed, are obviously related.
Code: Select all
Procedure MyProcedure()
ProcedureReturn 3, 4
EndProcedure
a, b = MyProcedure()
In the code snippet above, a working multiple assignment is the prerequisite for MyProcedure() to return 2 values this way.
And without the possibility of procedures returning multiple values, just being able to write
instead of
or something similar wouldn't be an advantage.
Danilo wrote:I'm learning the Rust programming language recently (started 2 month ago),
and what you are talking about here is called
Tuple's there:
Code: Select all
fn main() {
let tup = (500, 6.4, 1); // create tuple
let (x, y, z) = tup; // destructuring the tuple
println!("The value of y is: {}", y);
}
Yes,
that is advantageous!
But that would mean introducing a new data type into PB, so it's also a bit more than just being able to write something like
Re: multiple assignment
Posted: Sat May 09, 2020 11:56 am
by Little John
I have to correct myself. Apart from the possibility that procedures could return multiple values, and apart from the introduction of new datatypes into PureBasic, the following would be a use of multiple assignment that would really be a benefit:
Code: Select all
Procedure test()
Static a.Point = 1,2
Debug a\x
Debug a\y
EndProcedure
see
this thread
Re: multiple assignment
Posted: Sat May 09, 2020 12:33 pm
by Rinzwind
Similar with array assignment. Some c code is very ugly to translate to PB because PB can't assign or pass arrays declared inline.
Don't expect any language features added to PB, cause it barely happened before AFAIK. Only library additions and a module command without a global scope specifier.
Re: multiple assignment
Posted: Sat May 09, 2020 1:04 pm
by FlatEarth
Little John wrote:I have to correct myself. Apart from the possibility that procedures could return multiple values, and apart from the introduction of new datatypes into PureBasic, the following would be a use of multiple assignment that would really be a benefit:
Code: Select all
Procedure test()
Static a.Point = 1,2
Debug a\x
Debug a\y
EndProcedure
see
this thread
+1
Re: multiple assignment
Posted: Sat Jul 08, 2023 5:37 pm
by punak
+1
Re: multiple assignment
Posted: Sat Jul 08, 2023 5:43 pm
by Rinzwind
One can't even assign array values in one go, and you expect tuples? Way too modern for PB

Re: multiple assignment
Posted: Sat Jul 08, 2023 8:35 pm
by punak
I voted only for "multiple return" and "multiple assignment for variables".
I don't know the more complicated issues like arrays and so on , but I think the first two suggested are interesting.
This is my personal opinion.
Re: multiple assignment
Posted: Sat Jul 08, 2023 11:11 pm
by Demivec
I know this is a little bit divergent from the original post but that seems to be the way things are going.
I think that the assignments involving structures have value. My proposed changes are not extensive to cover every possibility and fit more in line with syntactic sugar. I provide some examples but not necessarily useful examples.
Code: Select all
;proposed syntax
;a new 'list expression type' is a list of comma separated values or expressions between { and }.
; strings
Define m.i = 12
Define k.s = "start" + {-3, "middle", Str(3 + 5), m}
Debug k ; outputs start-3middle812
Debug {"hello", 5, 2.0, 5 - 3, "done"} ;outputs hello52.00000002done
;arrays, single dimension only
Dim g.i(7), n.Point(3)
g(1) = {1, 3, 5, 4, 2, 0} ; set array elements 1 through 6
n.point(0) = {{9, -2}, {3 + 6, 2 * g(3)}, {-2, height}} ; set array elements 0 through 2
;NOT addressed are multidimensional array assignment.
;The further syntactic complexities that would need to be addressed include
;row order or column order and the assignments of less than a full set of elements.
;lists
NewList h.Point()
AddElement(h())
h.Point() = {6, 3} ; assign list element
:structures
Structure foo
a.s
b.f
c.i
Array d.i(5)
EndStructure
ReDim g(5) ; needs to match structure array size for next step
Define t.foo = {"real", 7.0, 2, g()} ; set structure elements
-1 for assignment of list of values to list of variables (more than one variable on left of equal sign)
+1 for multiple assignment to a structure or an array