The D Programming Language
Steve Wampler
sbw at naucse.UUCP
Thu Feb 18 00:41:56 AEST 1988
In article <2595 at haddock.ISC.COM>, karl at haddock.ISC.COM (Karl Heuer) writes:
> In article <563 at naucse.UUCP> sbw at naucse.UUCP (Steve Wampler) writes:
> >> > i(x1, x2, x3, ..., xn)
> >Actually, if 'i' is an arbitrary integral expression, it isn't that much more
> >expensive to implement than if it's a constant - most of the evaluation
> >expression for 'i' and a simple transfer.
> Sorry, I stand by my statement. If this `pick' operator is supposed to be a
> generalization of my proposed `,,' operator, it must preserve the guarantee of
> evaluating all of the `x?' operands, in left-to-right order. It sounds like
> you're thinking of the expression equivalent of `switch', which would evaluate
> exactly one of them. (Which may also be useful, but that's a separate topic.)
Actually, no. However, I wasn't thinking of this as an exact replacement
for the ',,' operator, just as something that does equivalent work. You
can evaluate all the operands and then fairly easily make an arbitrary one
of them available. Think of 'i(x1, x2, x3,..., xn)' as being analogous to
calling a function 'i' that returns its ith argument. Then think of ways
to avoid implementing 'i' as a function. I suppose that compared to the ',,'
operator, there is the overhead of verifying that 'i' evaluated to the
proper range, but that is really a cost of the extra generality, and can
be eliminated if 'i' is a constant.
Of course, the evaluation order for ',,' is well defined, while the
evaluation order (in 'C' at least) for 'i(...)' would match the evaluation
order for function calls, which is much messier. (In 'D', however....).
I think ',,' is an interesting operator, but I personnally prefer 'i(...)',
having used it extensively in Icon - it seems 'more natural' to me. To each
his own.
--
Steve Wampler
{....!arizona!naucse!sbw}
More information about the Comp.lang.c
mailing list