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

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

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

Alexander O. Melnik

127 apprezzamenti in 498 post.

Gruppo: 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) scaricato 1208 volta(e).
#2 Pubblicato: 13/11/2016 21:43:06
Davide Carpi

Davide Carpi

1.443 apprezzamenti in 2.936 post.

Gruppo: 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 Pubblicato: 13/11/2016 22:59:00
Alexander O. Melnik

Alexander O. Melnik

127 apprezzamenti in 498 post.

Gruppo: 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 Pubblicato: 13/11/2016 23:20:37
Jean Giraud

Jean Giraud

983 apprezzamenti in 6.866 post.

Gruppo: User

Forum Sum.gif
1 utenti hanno apprezzato questo post
Alexander O. Melnik 14/11/2016 17:20:00
#5 Pubblicato: 14/11/2016 00:53:25
Mike Kaganski

Mike Kaganski

184 apprezzamenti in 434 post.

Gruppo: User

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

Jean Giraud

983 apprezzamenti in 6.866 post.

Gruppo: User

... more conveniently and generalised.

Maths SUM.sm (10,68 KiB) scaricato 1230 volta(e).
1 utenti hanno apprezzato questo post
Alexander O. Melnik 14/11/2016 17:21:00
#7 Pubblicato: 14/11/2016 04:42:09
Davide Carpi

Davide Carpi

1.443 apprezzamenti in 2.936 post.

Gruppo: 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 utenti hanno apprezzato questo post
Alexander O. Melnik 14/11/2016 17:21:00
#8 Pubblicato: 14/11/2016 17:29:37
Alexander O. Melnik

Alexander O. Melnik

127 apprezzamenti in 498 post.

Gruppo: 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) scaricato 1205 volta(e).
FunctionBug1.png
#9 Pubblicato: 14/11/2016 17:50:23
Radovan Omorjan

Radovan Omorjan

325 apprezzamenti e 1 disapprezzamenti in 2.052 post.

Gruppo: 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 Pubblicato: 14/11/2016 18:06:10
Alexander O. Melnik

Alexander O. Melnik

127 apprezzamenti in 498 post.

Gruppo: 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 Pubblicato: 15/11/2016 02:40:00
Jean Giraud

Jean Giraud

983 apprezzamenti in 6.866 post.

Gruppo: User

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

Sum Unknown.gif
  • Nuovi post
  • Nessun nuovo post