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

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

#1 Objavljeno: 13. 11. 2016. 20:49:07
Alexander O. Melnik

Alexander O. Melnik

127 svidjanja u 498 postova.

Grupa: 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,33 KiB) preuzeto 1232 put(ova).
#2 Objavljeno: 13. 11. 2016. 21:43:06
Davide Carpi

Davide Carpi

1.444 svidjanja u 2.936 postova.

Grupa: 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 Objavljeno: 13. 11. 2016. 22:59:00
Alexander O. Melnik

Alexander O. Melnik

127 svidjanja u 498 postova.

Grupa: 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 Objavljeno: 13. 11. 2016. 23:20:37
Jean Giraud

Jean Giraud

983 svidjanja u 6.866 postova.

Grupa: User

Forum Sum.gif
1 korisnika je svidelo ovu objavu
Alexander O. Melnik 14. 11. 2016. 17:20:00
#5 Objavljeno: 14. 11. 2016. 00:53:25
Mike Kaganski

Mike Kaganski

184 svidjanja u 434 postova.

Grupa: User

Hey, in first block, you incremented ID by 1 in loop; in second you do it by self-incrementing i!
С уважением, Михаил Каганский
2 korisnika je svidelo ovu objavu
Davide Carpi 14. 11. 2016. 04:42:00, Alexander O. Melnik 14. 11. 2016. 17:21:00
#6 Objavljeno: 14. 11. 2016. 02:12:24
Jean Giraud

Jean Giraud

983 svidjanja u 6.866 postova.

Grupa: User

... more conveniently and generalised.

Maths SUM.sm (10,68 KiB) preuzeto 1250 put(ova).
1 korisnika je svidelo ovu objavu
Alexander O. Melnik 14. 11. 2016. 17:21:00
#7 Objavljeno: 14. 11. 2016. 04:42:09
Davide Carpi

Davide Carpi

1.444 svidjanja u 2.936 postova.

Grupa: 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 korisnika je svidelo ovu objavu
Alexander O. Melnik 14. 11. 2016. 17:21:00
#8 Objavljeno: 14. 11. 2016. 17:29:37
Alexander O. Melnik

Alexander O. Melnik

127 svidjanja u 498 postova.

Grupa: 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,67 KiB) preuzeto 1225 put(ova).
FunctionBug1.png
#9 Objavljeno: 14. 11. 2016. 17:50:23
Radovan Omorjan

Radovan Omorjan

325 svidjanja i 1 nesvidjanja u 2.052 postova.

Grupa: 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 Objavljeno: 14. 11. 2016. 18:06:10
Alexander O. Melnik

Alexander O. Melnik

127 svidjanja u 498 postova.

Grupa: 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 Objavljeno: 15. 11. 2016. 02:40:00
Jean Giraud

Jean Giraud

983 svidjanja u 6.866 postova.

Grupa: User

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

Sum Unknown.gif
  • Novi postovi
  • Nema novih postova