piet@cs.ruu.nl (Piet van Oostrum) (02/02/90)
In article <INFO-M2%90013108331746@UCF1VM.BITNET>, BARRY@LAUCOSC (Barry Adams) writes:
`Does anyone know why the BY expression in a FOR loop must be
`a constant expression? Is there some semantic reason?
If you want an answer to a question of the kind: Why is this or that not
possible in Pascal or Modula-2, the answer is usually: Because it is easier
to compile. If the BY expression is allowed to be a variable expression, it
could be either positive or negative at run time. So the compiler must
insert extra code to decide at runtime whether the loop will be ascending
or descending.
--
Piet* van Oostrum, Dept of Computer Science, Utrecht University,
Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands.
Telephone: +31-30-531806 Uucp: uunet!mcsun!hp4nl!ruuinf!piet
Telefax: +31-30-513791 Internet: piet@cs.ruu.nl (*`Pete')
TRL3@psuvm.psu.edu (Tim Larson) (02/02/90)
Questions of this type can often be answered by looking at the motivation behind the designer(s) of a programming language. I read an article once (which I tried to find, but could not), I think by Wirth or another person closely associated with the Lilith project, about why Modula-2 was designed. It seems to me that Modula-2 was designed for a specific project---as a high- level equivalent or substitute for assembler. The Lilith computer and the family of system languages that include Modula-2 were essentially designed together. For example, the Lilith has specific machine code instructions that aid in executing programs written in Modula-2 for the Lilith. Thus, although Wirth was motivated to write the best possible systems language for this project, that does not mean it is the best possible language for all systems. (Of course, "best possible" does not mean perfect or even uniquely best.) As it happened, however, Modula-2 got a lot of attention and was found to be relatively portable and (unlike Ada and C) simple. Now, Modula-2 has become more than just Wirth's language and is proceeding to an inter- national standard (just as Pascal did before it). Wirth has apparently moved on to a newer member of the Modula family called Oberon which simplifies the language even more, but at the same time adds some object-oriented features. Good Lord...I didn't mean to write this much, but I guess that the answer is that in many cases, Wirth designed features of the language to be closely coupled with a specific machine since it was the principle systems language of that machine. Consequently, simple things like BY have what may seem to us like odd semantic restrictions, though they would not be so odd in what is essentially an assembly language environment. (Stepping off my soapbox ...) -Tim Larson trl3@psuvm.bitnet P.S. If anyone can remember the article I mentioned from my rather limp description of it I am now dying to know. Naturally, this rambling article came from memory and I do not discount the possibility that a few cosmic rays may have scrambled some of my neurons over the years, so any inaccuracies are entirely due to me.
drori@altos86.Altos.COM (Ghiora Drori) (02/03/90)
The reason for designing the FOR the way (to the best of my knowledge) is so a reader can tell that you are going to be doing a fixed number of loops. If not you should use a While statement. In other words self documenting.@
abrodnik@watdragon.waterloo.edu (Andrej Brodnik (Andy)) (02/03/90)
Hi! Well, in fact the "BY" construct is not the only one which needs or asks for further comment: "Why "Father" didn't do in the other way". In fact there is no language structure in Modula-2 to which "no" question can be addressed. But more or less all the questions can be answered only by prof.Wirth himself. I remember (let us stay at discussion about "BY") that somebody mentioned something like: "If you would like to have a step of an "expression" length, then you should use a "WHILE" statement." Correct. But why don't you use "WHILE" statement in all cases? I think, that all this complaints are more or less guessings about the real intention of prof.Wirth design and they can be correctly answered only by him. In final stage they can be translated to the debate which language is the best. And such a debate is neverending. It is very similar to a trick which can parents use when their children insist to hear a fairy tale in the evening. For this purpose we use a comparisson between Story about a glass snail and Story about the angry snake. The first is more beutiful, while the second is longer. So you can play with your children as long as you would like. When he chooses one you propose him the second one. The similar story is when you are talking about the programming languages. We behave like children who always would like to hear the other story since it is better or easier or something else. But this behaviour runs the civilization further! Regards to all of you Andrej PS: Perhaps you didn't thing about the assembly language. In fact as much as you can do using any other language, you can do using it!
Pat.Terry@p101.f4.n494.z5.fidonet.org (Pat Terry) (02/05/90)
> >>Does anyone know why the BY expression in a FOR loop must be > >>a constant expression? Is there some semantic reason? What meaning would you like for FOR I := 1 TO 20 BY I DO WriteCard(I,3) END. Does your answer tie in with the meanings you would like/expect for I := 1; FOR I := I TO 20*I DO WriteCard(I, 3) END (I would expect the output 1 2 3 4 5 6 7 8 ... 19 20 <end> in this case) Just wondering. Pat -- uucp: uunet!m2xenix!puddle!5!494!4.101!Pat.Terry Internet: Pat.Terry@p101.f4.n494.z5.fidonet.org
Pat.Terry@p101.f4.n494.z5.fidonet.org (Pat Terry) (02/05/90)
> >Does anyone know why the BY expression in a FOR loop must be > >a constant expression? > > Another issue; is it illegal to have BY 0? Is this an infinite loop? The Draft Standard makes it illegal. -- uucp: uunet!m2xenix!puddle!5!494!4.101!Pat.Terry Internet: Pat.Terry@p101.f4.n494.z5.fidonet.org