1 Pages (2 items)
evaluation inside for and while loops - Messages
#1 Posted: 7/3/2012 7:11:47 AM
Hi,
I've found this strange behavior when you evaluate instructions inside for and while loops;
IMHO the direct evaluation ( = , -> ) inside loops could be (simply?) inhibited without any losses
regards,
w3b5urf3r

I've found this strange behavior when you evaluate instructions inside for and while loops;
IMHO the direct evaluation ( = , -> ) inside loops could be (simply?) inhibited without any losses
regards,
w3b5urf3r
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 users liked this post
kmihaylovich 7/3/2012 7:53:00 AM
#2 Posted: 7/3/2012 1:50:16 PM
Hi,
I guess that symbolic or numeric evaluation is already inhibited inside any expressions. Wherever you submit = or ->, the operator is put to the end of the complete expression, in this case at the end of the for or while loop or the if statement. In contrast to this, the assignment operator can be used in whatever substructures.
The odd result of for or while loops may be due to that these functions do not provide any return value. Attempt to assign the result of the control structure to a variable fails (syntax error). Perhaps the evaluation operators call a method that the control structure objects just do not provide. In UPN, if you want to use the result of some operation, you have to leave it on the stack. I guess that is where the error message comes from.
[MATH lang = eng]a:while(k<0,2+2)[/MATH]
The if statement returns the value of the corresponding branch and does neither fail to display it nor to provide it for assignment.
[MATH lang = eng]a:if(0<1,2+2,3+3)[/MATH]
results in
[MATH]a=4@#[/MATH]
Back to your proposal of inhibiting evaluation of control structures, an alternative might be to provide meaningful return values. The line operator returns the value of the last statement (what if that is a for loop
?
Loops might return the number of executions, for a while-loop that might occasionally save a separate counter, in a for loop this would be a bit redundant.
Best regards, Martin
WroteHi,
I've found this strange behavior when you evalutate instructions inside for and while loops;
IMHO the direct evalutation ( = , -> ) inside loops could be (simply?) inhibited without any losses
regards,
w3b5urf3r
I guess that symbolic or numeric evaluation is already inhibited inside any expressions. Wherever you submit = or ->, the operator is put to the end of the complete expression, in this case at the end of the for or while loop or the if statement. In contrast to this, the assignment operator can be used in whatever substructures.
The odd result of for or while loops may be due to that these functions do not provide any return value. Attempt to assign the result of the control structure to a variable fails (syntax error). Perhaps the evaluation operators call a method that the control structure objects just do not provide. In UPN, if you want to use the result of some operation, you have to leave it on the stack. I guess that is where the error message comes from.
[MATH lang = eng]a:while(k<0,2+2)[/MATH]
The if statement returns the value of the corresponding branch and does neither fail to display it nor to provide it for assignment.
[MATH lang = eng]a:if(0<1,2+2,3+3)[/MATH]
results in
[MATH]a=4@#[/MATH]
Back to your proposal of inhibiting evaluation of control structures, an alternative might be to provide meaningful return values. The line operator returns the value of the last statement (what if that is a for loop

Loops might return the number of executions, for a while-loop that might occasionally save a separate counter, in a for loop this would be a bit redundant.
Best regards, Martin
Martin Kraska
Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
1 Pages (2 items)
-
New Posts
-
No New Posts