1 Pages (11 items)
Feature or a bug? Cannot force numeric evaluation within a function - Messages
This example should be self explanatory. I expected same output in both cases. Is this a feature or a bug? Caused disaster in my formula logic.
Thanks!

FunctionBug.sm (7.33 KiB) downloaded 645 time(s).
Thanks!

FunctionBug.sm (7.33 KiB) downloaded 645 time(s).
Feature 
You are using pass-by-reference, that assign a value to an input argument when it is the target of an assignment inside the procedure (see here f.e.)

the last assignment is missing; to assign the same value both to the result and to the input variable you have to define ID#:eval(ID#+1) even after the loop.
![2016-11-14 01_53_10-2016-11-14 01_52_11-SMath Studio - [FunctionBug.sm_].png - Visualizzatore foto d.png](/zh-Hans-CN/files/Download/P6g35s/2016-11-14-01_53_10-2016-11-14-01_52_11-SMath-Studio---[FunctionBug.sm_].png---Visualizzatore-foto-d.png)
You are using pass-by-reference, that assign a value to an input argument when it is the target of an assignment inside the procedure (see here f.e.)

the last assignment is missing; to assign the same value both to the result and to the input variable you have to define ID#:eval(ID#+1) even after the loop.
![2016-11-14 01_53_10-2016-11-14 01_52_11-SMath Studio - [FunctionBug.sm_].png - Visualizzatore foto d.png](/zh-Hans-CN/files/Download/P6g35s/2016-11-14-01_53_10-2016-11-14-01_52_11-SMath-Studio---[FunctionBug.sm_].png---Visualizzatore-foto-d.png)
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
WroteFeature
You are using pass-by-reference, that assign a value to an input argument when it is the target of an assignment inside the procedure (see here f.e.)
the last assignment is missing; to assign the same value both to the result and to the input variable you have to define ID#:eval(ID#+1) even after the loop.
Davide, pass by reference assignment is intentional. What i do not understand is why
The result is 56 and not 10 - I used eval() to assign a static value to ID#, or so I thought, but ID# was assigned a dynamic ID# = ID# + 1, which was not the intent.
Hey, in first block, you incremented ID by 1 in loop; in second you do it by self-incrementing i!
С уважением,
Михаил Каганский
2 users liked this post
WroteDavide, pass by reference assignment is intentional. What i do not understand is why
The result is 56 and not 10 - I used eval() to assign a static value to ID#, or so I thought, but ID# was assigned a dynamic ID# = ID# + 1, which was not the intent.
Ah! Now I see it.
WroteHey, in first block, you incremented ID by 1 in loop; in second you do it by self-incrementing i!
This is the cause
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 users liked this post
Alexander O. Melnik 2016/11/14 17:21:00
Thank you all; so far I understood that something should be clear to me by now, but its not. What can I do to encapsulate a seemingly simple for() loop in a function that produces same result (10)?
FunctionBug1.sm (6.67 KiB) downloaded 631 time(s).

FunctionBug1.sm (6.67 KiB) downloaded 631 time(s).

1 Pages (11 items)
- New Posts
- No New Posts


