eval() and for/while loops

eval() and for/while loops - Сообщения

#1 Опубликовано: 28.05.2012 12:32:39
Davide Carpi

Davide Carpi

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

Группа: Moderator

Hi,

another little bug, I think...

bug eval() vs loops

note that the results are right (also for bigger scripts inside the loop)

here is the file in the example: bugs%2feval_for_0.94_debug.sm.zip


regards,

w3b5urf3r


If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#2 Опубликовано: 28.05.2012 20:26:29
Edward Ulle

Edward Ulle

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

Группа: Moderator

w3b,

I can't explain the error but I don't understand the eval()s. eval() is the same as "=".
Ed
#3 Опубликовано: 29.05.2012 00:15:51
Davide Carpi

Davide Carpi

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

Группа: Moderator

Hi WizEd

eval() speeds up the calculations (<10 seconds vs 20,30 seconds or minutes, if i remove all eval()s from entire script... i don't know how, but works :d )


regards,

w3b5urf3r
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#4 Опубликовано: 29.05.2012 13:14:28
Martin Kraska

Martin Kraska

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

Группа: Moderator

Wrote

Hi,

another little bug, I think...



Hi,

I am not sure if that is a bug or a feature. My theory on eval is that it enforces immediate evaluation when used on the right hand side of assignment operations. In your example, however, there is no assignment of the eval result. eval just tries to evaluate the statements inside the line operation and as a last step tries to determine the return value of the line operation (which is normally the value of the last line).

The last line, in your case, is a for statement, which is just a flow control statement and seems not to have a return value on it's own. Therefore, the last line has no return value and eval complains.

I may be totally wrong, still just providing any other line at the end resolves the error message.

eval(for)

Best regards, Martin Kraska
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
1 пользователям понравился этот пост
Radovan Omorjan 29.05.2012 14:41:00
#5 Опубликовано: 29.05.2012 18:11:53
Davide Carpi

Davide Carpi

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

Группа: Moderator

hi mkraska,

Thank you! I agree with your analysis

probably the use of eval() in the left side is not conventional, however the error message is quite obscure, I think o_o ...

for the visual error I had done differently, moving the eval() inside the for loop... in addition to eliminating the red border seems to be slightly faster, although I do not understand why (hundreds of eval() instead of one...)


best regards,

w3b5urf3r
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений