SMath Studio Forum
»
SMath Studio
»
Questions
»
Feature or a bug? Cannot force numeric evaluation within a function
Rank: Advanced Member Groups: Registered
Joined: 03/03/2014(UTC) Posts: 418 Was thanked: 125 time(s) in 96 post(s)
|
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 (8kb) downloaded 15 time(s).
|
|
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 13/01/2012(UTC) Posts: 2,654 Location: Italy Was thanked: 1340 time(s) in 879 post(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. Edited by user 14 November 2016 03:56:48(UTC)
| Reason: Not specified |
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects |
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 03/03/2014(UTC) Posts: 418 Was thanked: 125 time(s) in 96 post(s)
|
Originally Posted by: Davide Carpi 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. 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.
|
|
|
|
Rank: Guest
Groups: Registered
Joined: 04/07/2015(UTC) Posts: 6,866 Was thanked: 981 time(s) in 809 post(s)
|
|
1 user thanked Jean Giraud for this useful post.
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 17/01/2013(UTC) Posts: 296 Location: Khabarovsk, Russia Was thanked: 151 time(s) in 107 post(s)
|
Hey, in first block, you incremented ID by 1 in loop; in second you do it by self-incrementing i! |
Best regards, Mike Kaganski |
2 users thanked mikekaganski for this useful post.
|
on 14/11/2016(UTC), on 14/11/2016(UTC)
|
|
Rank: Guest
Groups: Registered
Joined: 04/07/2015(UTC) Posts: 6,866 Was thanked: 981 time(s) in 809 post(s)
|
... more conveniently and generalised. Maths SUM.sm (11kb) downloaded 15 time(s).
|
1 user thanked Jean Giraud for this useful post.
|
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 13/01/2012(UTC) Posts: 2,654 Location: Italy Was thanked: 1340 time(s) in 879 post(s)
|
Originally Posted by: Alex M. 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. Ah! Now I see it. Originally Posted by: mikekaganski Hey, in first block, you incremented ID by 1 in loop; in second you do it by self-incrementing i! This is the cause Edited by user 15 November 2016 01:35:21(UTC)
| Reason: marked as solved |
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects |
1 user thanked Davide Carpi for this useful post.
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 03/03/2014(UTC) Posts: 418 Was thanked: 125 time(s) in 96 post(s)
|
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 (7kb) downloaded 11 time(s).
|
|
|
|
Rank: Administration Groups: Registered, Advanced Member Joined: 23/06/2009(UTC) Posts: 1,740 Was thanked: 318 time(s) in 268 post(s)
|
Hello Alex M. I just hope that you did not see "1" - one instead if "i" in the loop. Was that the problem or something else? Regards, Radovan |
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!" |
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 03/03/2014(UTC) Posts: 418 Was thanked: 125 time(s) in 96 post(s)
|
Originally Posted by: omorr Hello Alex M. I just hope that you did not see "1" - one instead if "i" in the loop. Was that the problem or something else? Regards, Radovan I was blind as a mole. Thanks Edited by user 15 November 2016 21:45:16(UTC)
| Reason: Not specified
|
|
|
|
Rank: Guest
Groups: Registered
Joined: 04/07/2015(UTC) Posts: 6,866 Was thanked: 981 time(s) in 809 post(s)
|
I'm sure something I don't understand in there, i.e: in what you are trying to do !
|
|
|
|
SMath Studio Forum
»
SMath Studio
»
Questions
»
Feature or a bug? Cannot force numeric evaluation within a function
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.