[DGD] Re: Counting from the end in arrays....

Kris Van Hees aedil at alchar.org
Tue Sep 22 15:22:44 CEST 1998


On Tue, Sep 22, 1998 at 11:33:22AM +0200, Tim Blommerde wrote:
> Got another question for you regarding the DGD variant of LPC.  My question
> is if it's possible to get a certain amount of members counting from the end
> of the array.  For example the last member, or the last three members.  And
> all this without first determining the size of the array.  I know you could
> do something like this:
>     array[ sizeof(array)-3 .. sizeof(array)-1]
> But I want to know if something like this is possible (Amylaar solution):
>     array[<3 .. <1]

This has been looked into in the past, for sure.  Or rather, I know that the
issue has been raised with Dworkin around the time he was working on getting
the a-series stable.  While it is convenient to have a construct like  this,
the gains from it are very little (if any).  After all, while it results  in
shorter code and only one kfun call (range), the alternative is:

	array[sizeof(array) - 3 ..]

which in effect is three kfun calls (subtraction, sizeof, range).  They  are
cheap enough though to not really make that much of a difference.  And it is
also so very easy to provide an emulation through a function, like  the  old
slice_array().

Other than this, Dworkin probably has other reasons for it also.  His  memory
on these discussions with people on The Pattern is probably much better.
> 
> If not such a thing is possible, would if be hard to add either as a package
> or maybe as a standard thing in the dgd driver (Mr. Dworkin ?).

Adding it in the form you present isn't something you can just do with a pkg
because it's not just at the kfun level.  In order to accept the '< num'  in
code, a change must be made to the yacc parser, and the array handling code.

Aedil



List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list