karl@haddock.ISC.COM (Karl Heuer) (01/28/88)
In article <9998@ccicpg.UUCP> nick@ccicpg.UUCP (Nick Crossley) writes: >While we are inventing other types of and syntax for assignment, >what about the [Algol68C] 'displacement' operator [":=:=", which stores >a new value but returns the old value]? Well, I suppose it's time for me to plug my double-comma operator again. Some years ago I invented the hypothetical notation "e1 ,, e2", which would be like the comma operator in that it evaluates its left operand before its right operand, but (unlike comma) the result would be the value of the left operand. Look what this buys us: a,, a=b /* displacement operator, like a :=:= b */ a=(b,, b=a) /* a simple swap */ x,, ++x /* same as x++; but generalizable */ free(stack,, stack=stack->next) /* pop stack */ stack->value,, pop(stack) /* pop and return stacked value */ There's some code in the terminfo routines that wants to do #define getshi() *((short *)ip)++ but since this is illegal on two counts, it instead uses #define getshi() getsh(ip); ip += 2 (this kludge depends on the fact that it is always called via "x = getshi();", which will expand into "x = getsh(ip); ip += 2"). Given a reverse sequential evaluation operator, this could have been written #define getshi() getsh(ip,, ip += 2) or, if ip is known to be aligned, #define getshi() *((short *)ip,, ip += 2) , either of which would be usable in any expression context. Of course, the code generated for ",," is almost as simple as for ","; the straightforward approach just needs a temporary (a scratch register, or top of stack). Of course, if the ultimate destination is already free, the temporary can be optimized out: f(x,,y) becomes push(x); eval(y); call(f). Using an HLL means never having to declare a temporary... Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint
schwartz@gondor.cs.psu.edu (Scott E. Schwartz) (01/29/88)
In article <2411@haddock.ISC.COM> karl@haddock.ima.isc.com (Karl Heuer) writes: >In article <9998@ccicpg.UUCP> nick@ccicpg.UUCP (Nick Crossley) writes: >Some years ago I invented the hypothetical notation "e1 ,, e2", which would be >like the comma operator in that it evaluates its left operand before its >right operand, but (unlike comma) the result would be the value of the left >operand. My off the cuff feeling is that this is a good idea. I have often wished for something like this, particularly when trying to write complicated macro expressions with lots of side effects (and better off written as functions, to boot! :-) ) (Remember the pascal to c translator posted to comp.sources.unix last summer? Anyone notice that the code for terminal IO was totally wrong? The reason was that the author used the "," operator as if it behaved like ",," in several places.) Naturally I expect the reply to this suggestion is going to be "try C++". -- Scott Schwartz schwartz@gondor.cs.psu.edu
wes@obie.UUCP (Barnacle Wes) (01/31/88)
In article <2411@haddock.ISC.COM>, karl@haddock.ISC.COM (Karl Heuer) writes: > In article <9998@ccicpg.UUCP> nick@ccicpg.UUCP (Nick Crossley) writes: > >While we are inventing other types of and syntax for assignment Sperry (pre-Unisys days) used to have a Pascal-like compiler for some of their cluster controllers that supported the :=: operator, which swapped the two values surrounding it. I do not know what it returned as a value. (i.e., `a :=: b' was equivalent to `swap(a, b)'). Wes Peters {ihnp4, seismo}!utah-cs!utah-gr!uplherc!sp7040!obie!wes