From: Virgil on
In article <Virgil-4FAC6C.17565710012010(a)bignews.usenetmonster.com>,
Virgil <Virgil(a)home.esc> wrote:

> In article
> <dbfcb94b-a6c0-4dbe-8780-d8cecaba22a4(a)j19g2000yqk.googlegroups.com>,
> TW <timwessman(a)gmail.com> wrote:
>
> > I was fiddling with something today and found myself needing to remove
> > an item from a list at a given index location and was surprised not to
> > find a command that would do it. Am I missing one that is right in
> > front of me?
> >
> > I was looking for something that would remove item N from a list, and
> > preferably not modify the list if 0 < N or N >MAX_SIZE or something
> > like that. It kind of surprised me I didn't see one. As a workaround I
> > made a little routine that does a SUBCOMP on either side and puts them
> > together, but that isn't very nice. . .
> >
> > TW
>
> Try this program with the list and the position, in that order, on the
> stack:
>
> \<< \-> n
> \<< 1
> \<< n NSUB == {DROP} IFT
> \>>
> DOSUBS
> \>>
> \>>
>
> Note that the program will not do anything when the list position is
> below 1 or above the number of elements listed.

I have found a much better program thatn the above to do the same thing.
The one above misbehaves, leaving no set at all if you try to remove the
first element from a one element set.

Try the following short program with the list and the position to be
deleted, in that order, on the stack:

\<< DUP2 1 SWAP 1 - SUB UNROT 1 + OVER SIZE SUB + \>>
From: John H Meyers on
Andreas Moeller:

> exploding and rebuilding the composite is the fastest way in SYS-RPL

Or even in UserRPL.

The following (UserRPL) came from... (well, I forgot where):

@ { list } N -> delete item N from list
\<< SWAP LIST\-> 1 - DUP DUP 4 + ROLL - 3 + ROLL DROP \->LIST \>>

Both SysRPL and 49/50 series UserRPL have a DUPDUP command, FWIW.

Bounds checking is not included, but can be added.

Another similar UserRPL version that's often been posted
will accept a larger number N than the list size,
yet not stop on error even if nothing else is initially on the stack.

[r->] [OFF]
From: CesarV on
On 10 ene, 16:49, TW <timwess...(a)gmail.com> wrote:
> I was fiddling with something today and found myself needing to remove
> an item from a list at a given index location and was surprised not to
> find a command that would do it. Am I missing one that is right in
> front of me?
>
> I was looking for something that would remove item N from a list, and
> preferably not modify the list if 0 < N or N >MAX_SIZE or something
> like that. It kind of surprised me I didn't see one. As a workaround I
> made a little routine that does a SUBCOMP on either side and puts them
> together, but that isn't very nice. . .
>
> TW

You can use this
The objects in the stack are showed at the rigth

* Del the element of the position #i in the composite.
* (#i is the position from the left)
NULLNAME DelInComposite ( {} #i -> {}' )
::
DUP#0= ( {} #i flag )
3PICK ( {} #i flag {} )
LENCOMP ( {} i# flag #len )
3PICK ( {} i# flag #len i# )
#< ( {} i# flag flag' )
OR ( {} i# flag'' )
caseDROP ( {} ) ( exit of secondary )
( {} i# )
SWAPINCOMP ( i# meta )
DUPDUP ( i# meta #n #n )
#3+ ( i# meta #n #n+3 )
ROLL ( meta #n #i )
#- ( meta #n-i )
#2+ ( meta #n-i+2 )
ROLLDROP ( ........ #n )
#1- ( meta' )
{}N ( {}' )
;

_____________________
César Vásquez Alvarado
Lima Perú
Visit the forum: http://honradoshp.foroactivo.com/
Visit my page: http://cesarv.jimdo.com/
First  |  Prev  | 
Pages: 1 2
Prev: Debug4x How to compress?
Next: Gaak.org, The Return