Domanda

I'm doing a "programming languages" course (just started) and I have this question which I honestly have no idea how to answer. I have these 2 options:

 write(p1, p2, ......, pn)

and this one:

 begin write(p1); write(p2); ....... write(pn); end

what I'm supposed to do is give an example for expressions p1, p2, ..., pn so the program will behave differently for each of these options. I would love some help with this.

(This is not a part of some bigger program, these 2 lines are all I have. I'm not all that familiar with Pascal, and I'm not supposed to be, that's not the intention of the course. so if you write an answer I will appreciate if you don't assume I know the language. I only know some basics.)

È stato utile?

Soluzione

This is not an answer, as I don't think it's fair to do other people's homework. It's sort of a hint, so that you can find the answer yourself.

At a first glance, these two pieces of code seem to be equivalent. At a second one, they may not be. In which order are p1, p2, ..., pn evaluated in each piece of code? If the order is not (necessarily) the same, does it matter? Can you choose p1, p2, etc. so that it matters in which order you evaluate them?

I assume that the purpose of this exercise is not to teach you Pascal, but to teach you about evaluation order and how different languages specify it (or do not specify it).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top