ID:2958911
 
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
Proposed Syntax

proc/Example()
return list(123,321,444)

mob/Login()
var a,b,c = Example()
world << a // 123
world << b // 321
world << c // 444
I like destructuring assignment as a Thing and "var {a; b; ...}" form does exist for multiple variable declaration (eg this dm reference entry) and so you could perhaps hope for "var {a;;b;...c} = something" where ";;" is a positional skip and ...c is a remaining list collector - assigning only to a if "something" isn't a (flat) list.

It's *probably* more trouble than it's worth though. :P
I think I get the point of this feature request.
They want a proc returning multiple values, and automatically set into multiple variables.
So, ideally, we wouldn't want to return a list, but a way to let a proc to return multiple values to calling variables...

I am not sure if a dm internal feature would be good for this, but it is partially feasible as a pointer if someone wants a proc doing such.

#define set3vars(a, b, c) _set3vars(&a, &b, &c) // this is a handy way to take variables without putting & into proc arguments
/proc/_set3vars(a, b, c)
*a = 11
*b = 23
*c = 34

/proc/main()
var/a
var/b
var/c
set3vars(a, b, c)
world.log << "[a] / [b] / [c]"


This is technically not a proc returning, but pointers will be possible to handle multiple variables. Using a list having pointers can be a way.

but I am not sure what's worth between pointers v.s. new internal assignment feature
Currently I do.

proc/ImageColorData(image)
//...
return list(list(),list(),list())

var temp_list = ImageColorData(image)

var red_pixels = temp_list[1]
var green_pixels = temp_list[2]
var blue_pixels = temp_list[3]



While below would save space and help with readability plus it's more logical to look at lol.


proc/ImageColorData(image)
//...
return list(list(),list(),list())

var red_pixels, green_pixels, blue_pixels = ImageColorData(image)


It could also be utilized in many other situations I would think.

Maybe the values returned could be seperated differently such as

proc/ImageColorData(image)
//...
return list(), list(), list()
In response to EvilDragonfiend
EvilDragonfiend wrote:
I think I get the point of this feature request.

What you have is close to out parameters, which (practically) by-ref-ify by-value parameters.

What they're asking for is destructuring/unpacking but from a python background, which wraps multiple comma separated returns in an invisible tuple for you :b

Login to reply.