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

Feature or a bug? Cannot force numeric evaluation within a function - Сообщения

#1 Опубликовано: 13.11.2016 20:49:07
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: 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 КиБ) скачан 27 раз(а).
#2 Опубликовано: 13.11.2016 21:43:06
Davide Carpi

Davide Carpi

1416 сообщений из 2873 понравились пользователям.

Группа: 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 Опубликовано: 13.11.2016 22:59:00
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: 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 Опубликовано: 13.11.2016 23:20:37
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Forum Sum.gif
1 пользователям понравился этот пост
Alexander O. Melnik 14.11.2016 17:20:00
#5 Опубликовано: 14.11.2016 00:53:25
Mike Kaganski

Mike Kaganski

184 сообщений из 434 понравились пользователям.

Группа: User

Hey, in first block, you incremented ID by 1 in loop; in second you do it by self-incrementing i!
С уважением, Михаил Каганский
2 пользователям понравился этот пост
Davide Carpi 14.11.2016 04:42:00, Alexander O. Melnik 14.11.2016 17:21:00
#6 Опубликовано: 14.11.2016 02:12:24
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

... more conveniently and generalised.

Maths SUM.sm (10 КиБ) скачан 27 раз(а).
1 пользователям понравился этот пост
Alexander O. Melnik 14.11.2016 17:21:00
#7 Опубликовано: 14.11.2016 04:42:09
Davide Carpi

Davide Carpi

1416 сообщений из 2873 понравились пользователям.

Группа: 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 пользователям понравился этот пост
Alexander O. Melnik 14.11.2016 17:21:00
#8 Опубликовано: 14.11.2016 17:29:37
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: 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 КиБ) скачан 29 раз(а).
FunctionBug1.png
#9 Опубликовано: 14.11.2016 17:50:23
Radovan Omorjan

Radovan Omorjan

325 сообщений из 2052 понравились пользователям.

Группа: 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 Опубликовано: 14.11.2016 18:06:10
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: 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 Опубликовано: 15.11.2016 02:40:00
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

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

Sum Unknown.gif
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений