for loop

for loop - Messages

#1 Posted: 11/16/2013 3:40:08 AM
alberich

alberich

0 likes in 2 posts.

Group: User

Hello,

I am new to smath and may probably have missed something relating to the syntax.
However, the following result surprised me and I am quite curious why I get this result.
remark: I use smath under linux (debian).

al
for loop.jpg
#2 Posted: 11/16/2013 5:34:04 AM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

Wrote

Hello,

I am new to smath and may probably have missed something relating to the syntax.
However, the following result surprised me and I am quite curious why I get this result.
remark: I use smath under linux (debian).

al


Interesting question. I never used lists (systems) to make instruction blocks. As your example demonstrates, the entries in a list (as well as in matrices) are evaluated in reverse sequence.

In the first loop iteration, z is not defined and stored symbolically in b[1;1, then z is set to 1
After leaving the loop, z has the value 9, which is substituted for z when you evaluate b. You see that if you hover with the mouse over the loop statement.

If you reverse the entries, you get the expected behaviour.

Normally you are supposed to use the line() function for instruction blocks. The elements are evaluated top-down and the block has the result of the last statement as return value.

EDIT:

It seems that there are severe operator spacing problems under linux. Between variable and array index there should be more space in order to distinguish such indices from text indices. Also, the := in the loop header look like = because the : is printed over the preceeding operator. You might experiment with the dpi settings.
line.sm (7 KiB) downloaded 211 time(s).
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#3 Posted: 11/17/2013 3:36:31 AM
alberich

alberich

0 likes in 2 posts.

Group: User

Thank you for the quick reply.
al
  • New Posts New Posts
  • No New Posts No New Posts