Feature or a bug? Cannot force numeric evaluation within a function

Feature or a bug? Cannot force numeric evaluation within a function - Messages

#1 Posted: 11/13/2016 8:49:07 PM
Alexander O. Melnik

Alexander O. Melnik

127 likes in 494 posts.

Group: Moderator

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.png
FunctionBug.sm (7 KiB) downloaded 28 time(s).
#2 Posted: 11/13/2016 9:43:06 PM
Davide Carpi

Davide Carpi

1416 likes in 2873 posts.

Group: Moderator

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.)

2016-11-14 01_50_19-Feature or a bug_ Cannot force numeric evaluation within a function.png

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
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
Alexander O. Melnik

Alexander O. Melnik

127 likes in 494 posts.

Group: Moderator

Wrote

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.)

2016-11-14 01_50_19-Feature or a bug_ Cannot force numeric evaluation within a function.png

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



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.
#4 Posted: 11/13/2016 11:20:37 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Forum Sum.gif
1 users liked this post
Alexander O. Melnik 11/14/2016 5:20:00 PM
#5 Posted: 11/14/2016 12:53:25 AM
Mike Kaganski

Mike Kaganski

184 likes in 434 posts.

Group: User

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
Davide Carpi 11/14/2016 4:42:00 AM, Alexander O. Melnik 11/14/2016 5:21:00 PM
#6 Posted: 11/14/2016 2:12:24 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

... more conveniently and generalised.

Maths SUM.sm (10 KiB) downloaded 29 time(s).
1 users liked this post
Alexander O. Melnik 11/14/2016 5:21:00 PM
#7 Posted: 11/14/2016 4:42:09 AM
Davide Carpi

Davide Carpi

1416 likes in 2873 posts.

Group: Moderator

Wrote

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.

Wrote

Hey, 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
Alexander O. Melnik

Alexander O. Melnik

127 likes in 494 posts.

Group: Moderator

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.png
#9 Posted: 11/14/2016 5:50:23 PM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

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?

onenoti.png

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#10 Posted: 11/14/2016 6:06:10 PM
Alexander O. Melnik

Alexander O. Melnik

127 likes in 494 posts.

Group: Moderator

Wrote

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?

onenoti.png

Regards,
Radovan



I was blind as a mole. Thanks
#11 Posted: 11/15/2016 2:40:00 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

I'm sure something I don't understand in there,
i.e: in what you are trying to do !

Sum Unknown.gif
  • New Posts New Posts
  • No New Posts No New Posts