[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Aug 17 11:57:35 1993 
Subject:delete_nth 
From:jonr (Jonathan Rowe) 
Volume-ID:930817.05 


Now this is getting silly....


uses newqueue;

define delete_nth( n, L ); lvars n L;
    expandlist( pdtolist(                       ;;; expand the dynamic list
                                                ;;; made from the following:
        procedure( q, n, counter ) -> result;
            lvars q n counter result;
            q() -> result;                      ;;; get the next item
            if n = counter.cont then            ;;; is it the one?
                q() -> result;                  ;;; if so get the next one
            endif;
            counter.cont + 1 -> counter.cont;   ;;; update the counter
        endprocedure(% newqueue( L.copylist ), n, consref( 1 ) %)
    ))
enddefine;


However, Jonathan Cunningham says that if you're going to use NEWQUEUE
you should do it like this:

define delete_nth( n, l);
lvars n, l;     ;;; what's wrong with lower case l - I like them!!
lvars L;        ;;; let's have an uppercase as well :-)
    length( l ) -> L;
    newqueue( l.copylist ) -> l;
    repeat n - 1 times l() -> l(); endrepeat;
    l()->;
    repeat L - n times l() -> l(); endrepeat;
    qlist( l );
enddefine;