Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline Davide Carpi  
#1 Posted : 03 July 2012 14:11:47(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,647
Man
Italy
Location: Italy

Was thanked: 1329 time(s) in 875 post(s)
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

Edited by user 18 September 2012 01:36:14(UTC)  | Reason: Not specified

File Attachment(s):
loops debug.sm (7kb) downloaded 15 time(s).
Davide Carpi attached the following image(s):
evalutation.PNG
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
thanks 1 user thanked Davide Carpi for this useful post.
on 03/07/2012(UTC)

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline mkraska  
#2 Posted : 03 July 2012 20:50:16(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,986
Germany

Was thanked: 1124 time(s) in 721 post(s)
Hi,

Originally Posted by: w3b5urf3r_reloaded Go to Quoted Post
Hi,

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.

a:while(k<0,2+2)

The if statement returns the value of the corresponding branch and does neither fail to display it nor to provide it for assignment.

a:if(0<1,2+2,3+3)

results in

a=4@#

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 Wink?

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://smath.com/wiki/SMath_with_Plugins.ashx
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.