1 страниц (11 вхождений)
Feature or a bug? Cannot force numeric evaluation within a function - Сообщения
#1 Опубликовано: 13.11.2016 20:49:07
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 (7 КиБ) скачан 29 раз(а).
Thanks!
FunctionBug.sm (7 КиБ) скачан 29 раз(а).
#2 Опубликовано: 13.11.2016 21:43:06
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.
![2016-11-14 01_53_10-2016-11-14 01_52_11-SMath Studio - [FunctionBug.sm_].png - Visualizzatore foto d.png](/ru-RU/file/P6g35s/2016-11-14-01_53_10-2016-11-14-01_52_11-SMath-Studio---_FunctionBug_sm___png---Visualizzatore-foto-d_png)

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.
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
WroteFeature
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.
#4 Опубликовано: 13.11.2016 23:20:37
1 пользователям понравился этот пост
Alexander O. Melnik 14.11.2016 17:20:00
#5 Опубликовано: 14.11.2016 00:53:25
Hey, in first block, you incremented ID by 1 in loop; in second you do it by self-incrementing i!
С уважением,
Михаил Каганский
2 пользователям понравился этот пост
#6 Опубликовано: 14.11.2016 02:12:24
1 пользователям понравился этот пост
Alexander O. Melnik 14.11.2016 17:21:00
#7 Опубликовано: 14.11.2016 04:42:09
WroteDavide, 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.
WroteHey, 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
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 КиБ) скачан 30 раз(а).

FunctionBug1.sm (6 КиБ) скачан 30 раз(а).
#9 Опубликовано: 14.11.2016 17:50:23
#10 Опубликовано: 14.11.2016 18:06:10
#11 Опубликовано: 15.11.2016 02:40:00
1 страниц (11 вхождений)
-
Новые сообщения
-
Нет новых сообщений