Hi Peter, Hugh Chief, Howdy the list.
I think one good reason why peoples interested in programming should know a bit about compilers is that they hence have an idea how to write their code so that the compilated version of it won't be too bad.
I know damn shit about compilers, but there is this situation I am always perplex about when facing it. Suppose "call" is a big complicated function, say, a theta(2**n) one, really the big one. How will GPC translate the following line into machine code?
if call(a)=1 or call(a)=2 then ...
Will it call two times the function? Or will it by itself do the simplification? Should we by ourselves complicate our way of writting code in defining another variable to store in advance the result of call(a)?
Cheers (and thanks Peter for your proposal of implementing set of records, I use something near it, it works fine).
F.P.L
According to FPL:
I think one good reason why peoples interested in programming should know a bit about compilers is that they hence have an idea how to write their code so that the compilated version of it won't be too bad.
Be welcome to browse through the GPC source! Yes, seriously! See `info -f gpc -n "GPC source" for an entry point.
I know damn shit about compilers, but there is this situation I am always perplex about when facing it. Suppose "call" is a big complicated function, say, a theta(2**n) one, really the big one. How will GPC translate the following line into machine code?
if call(a)=1 or call(a)=2 then ...
GPC will produce "short circuit" operations by default which means that the second `call(a)' is not evaluated at all if the first one already returned `true'. Otherwise, `call(a)' will be called a second time because GPC cannot know that it will return the same result as before. (Substitute, for instance, BP's `random' function for `call'.;-)
This can be turned off with a $B+ directive (like in BP) or with a command-line switch `--no-short-circuit'.
According to ISO standard, you must not rely on this specific behavior. The operands of `or' might be evaluated in any order, or not at all.
[...] Should we by ourselves complicate our way of writting code in defining another variable to store in advance the result of call(a)?
Yes. In order to get a defined behaviour in a portable way, you must do that.
Cheers (and thanks Peter for your proposal of implementing set of records, I use something near it, it works fine).
:-)
Greetings,
Peter