grzegorzmazur / yacas

Computer calculations made easy
http://www.yacas.org
GNU Lesser General Public License v2.1
126 stars 24 forks source link

ForEach(i, 1 .. n) or similar is probably always wrong #333

Closed Isomorph70 closed 3 years ago

Isomorph70 commented 3 years ago

If the programmer's intent is to go through 1 to n, then he expects no loops in case of n=0, but (1 .. n) will produce the vector {1,0} when n=0, which can result in an error.

To reduce this error source, all statement of the form ForEach(i, 1 .. n) should be exchanged with For(i:=1,i<=n, i++) or similar.

Also (1 .. n) makes a vector, that take up more space, than a single integer variable.

PS. I have started to fix the scripts, hope to commit in a couple of days.

Isomorph70 commented 3 years ago

https://github.com/grzegorzmazur/yacas/pull/334