[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Aug 17 09:49:20 1993 
Subject:Re: delete_nth 
From:Steve Knight 
Volume-ID:930817.03 

jonr (Jonathan Rowe) (jonr@uk.co.bmtech) wrote:
> Here's my (elegant?) way of deleting the nth item of a list:
> define delete_nth( l, n );
>     lvars l n unique;
>     sysNEW_LVAR() ->> l(n) -> unique;
>     delete( unique, l );
> enddefine;

A lovely idea, flawed only by the existance of lib showcode AND the
requirement that the original spine is left unchanged (whoops).  However,
it can easily be repaired ...

define delete_nth( n, L );              ;;; Get args in preferred order :-)
    lvars n, L;                         ;;; Never use lower case L because
                                        ;;;   of confusion with 1.
    lvars unique = nullstring.copy;
    L.copylist -> L;                    ;;; Copy the spine.
    unique -> L( n ); 
    delete( unique, L, nonop == )
enddefine;

Of course, this can be compacted for ``greater'' elegance!

define delete_nth( n, L ); lvars n, L;
    delete( nullstring.copy ->> (L.copylist ->> L)( n ), L, nonop == )
enddefine;

And to avoid having to specify "==" as the operator, as in Jonathan's
original concept, we should replace nullstring by a value which is only
"=" if it is "==".  And *voila* -- sheer elegance .....

define delete_nth( n, L ); lvars n, L;
    delete( identfn.copy ->> (L.copylist ->> L)( n ), L )
enddefine;

Steve