lunedì, agosto 22, 2016

Self-Redefinition in DesignScript

I just stumbled upon this interesting fact of the default language block you have in Code Blocks:

It looks kind of weird at first right? you would expect that the result is 1, not 2, if you do the same in a Python script you have right 1:



Note how there is only one output port on the Code Block, this is because the variable in play is called x on both lines, plus the default language block is Associative which means that each assignment is re-executed, some sort of recursion, to update all the variables values.

At first x = 0, on the second line the same variable x is then assigned to an expression x + 1, which returns x = 1, but since 1 is different form 0 it means that the value associated to x has changed so the Associativity kicks in and it re-executes the assignment that yields 1 + 1 = 2   which is totally correct in terms of DesignScript Associative language block context.

There are a couple of options to get the "standard" value 1 out of a Code Block:



Look at the number of output ports on the right side of these Code Blocks, just be thoughtful when you are using DesignScript because you need to know its own rules.



Nessun commento:

Posta un commento