top of page
Search

Multi-value assignment

Writer: Ivaylo FizievIvaylo Fiziev

We all know that values are assigned to variables using the assign (:=) operator. But do you know that the assign operator may be used multiple times in a single assignment statement? This is what multi- value assignment is all about. It saves you lines of code by doing all the assignments in one line. In the context of the script this also means faster execution since the parse tree becomes shallow. Finally in v2509 we have support for it.

Of course the variables that you reference should be of the same type. In case of arithmetic types values will be cast to the target type prior assignment. Here is how it works:


Imagine you have a situation like this:

#a := BYTE#0; // variable of type BYTE 
#b := UINT#0; // variable of type UINT

#a := #b := 2048; // what will be the result?

In case you use different variable types you may be surprised by the result.

The value of #a will be incorrect for sure since you cannot fit this value in a byte. The value of #b however will be correct. The assignment is done from right to left. e.g. the value of 2048 will be cast to UINT first and assigned to #b. Then the value of #b will be cast to BYTE and will be assigned to #a. The last cast causes loss of data.

If you change the order of the assignment both variables will have wrong values since the value of #a will dictate the value of #b.

If types are not compatible you'll get an error.

On the UI side semantic code completion still works so you can get a list of variable/function names as you type. Pretty cool, isn't it? I wish we had this long ago...

Try it !


Довиждане и до нови срещи!



 
 
 

Comentarios

Obtuvo 0 de 5 estrellas.
Aún no hay calificaciones

Agrega una calificación

Subscribe Form

Thanks for submitting!

bottom of page