1 Pages (11 items)
Feature or a bug? Cannot force numeric evaluation within a function - Messages
#1 Posted: 11/13/2016 8:49:07 PM
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 KiB) downloaded 28 time(s).
Thanks!
FunctionBug.sm (7 KiB) downloaded 28 time(s).
#2 Posted: 11/13/2016 9:43:06 PM
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](/en-US/file/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.
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#3 Posted: 11/13/2016 10:59:00 PM
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.
#5 Posted: 11/14/2016 12:53:25 AM
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
#7 Posted: 11/14/2016 4:42:09 AM
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 11/14/2016 5:21:00 PM
#8 Posted: 11/14/2016 5:29:37 PM
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 KiB) downloaded 29 time(s).

FunctionBug1.sm (6 KiB) downloaded 29 time(s).
#9 Posted: 11/14/2016 5:50:23 PM
#10 Posted: 11/14/2016 6:06:10 PM
#11 Posted: 11/15/2016 2:40:00 AM
1 Pages (11 items)
-
New Posts
-
No New Posts