MiniM. Saving time.


| About | Download | Tools | Knowledge Base | How to Buy |

MiniM Overview

Getting Started

Download

Documentation

Tools

Cache Tools

GT.M Tools

Knowledge Base

FAQ

Contacts

Copyrights

MiniM Knowledge Base | Oct 11, 2010

How to remove and insert list elements

Question. If we have a list created by $listbuild() function, how to insert other elements in the specified position or remove position? How to get sublist of list?

Answer. All this do the 3-argument form of the $list() function.

Remove list element in the N position:
s $list(list,N,N)=""
Example:
USER>s list=$lb(1,2,3,4)
USER>s $li(list,2,2)=""
USER>f i=1:1:$ll(list) w $lg(list,i,"undef"),!
1
3
4
Remove list elements from position N to position M inclusively:
s $list(list,N,M)=""
Example:
USER>s list=$lb(1,2,3,4)
USER>s $li(list,2,3)=""
USER>f i=1:1:$ll(list) w $lg(list,i,"undef"),!
1
4
Replace elements from position N to position M by one element val:
s $list(list,N,M)=$lb(val)
Example:
USER>s list=$lb(1,2,3,4)
USER>s $li(list,2,3)=$lb(5)
USER>f i=1:1:$ll(list) w $lg(list,i,"undef"),!
1
5
4
Insert instead of list elements from position N to position M several list elements val1, val2, ...
s $list(list,N,M)=$lb(val1,val2,...)
Example:
USER>s list=$lb(1,2,3,4)
USER>s $li(list,2,3)=$lb(5,6,7,8)
USER>f i=1:1:$ll(list) w $lg(list,i,"undef"),!
1
5
6
7
8
4
If we need insert list elements without replacing, only by expanding list, we can use replace operation with first element of replacement, Example:
USER>s list=$lb(1,2,3,4)
USER>s $list(list,2,2)=$lb(5,6,$li(list,2))
USER>f i=1:1:$ll(list) w $lg(list,i,"undef"),!
1
5
6
2
3
4
How to get sublist of list from position N to position M inclusively:
$list(list,N,M)
Example:
USER>s list=$lb(1,2,3,4)
USER>s li=$li(list,2,3)
USER>f i=1:1:$ll(li) w $lg(li,i,"undef"),!
2
3
Id we need to get sublist up to last element inclusively, we must specify in the thord argument value of -1, for example:
USER>s list=$lb(1,2,3,4)
USER>s li=$list(list,2,-1)
USER>f i=1:1:$ll(li) w $lg(li,i,"undef"),!
2
3
4
If numbers of positions are outside available in source list, the $list() function automatically make padding of list element by empty positions. Example:
USER>s list=$lb(1,2,3,4)
USER>s $li(list,8,9)=$lb(5,6,7)
USER>f i=1:1:$ll(list) w $lg(list,i,"undef"),!
1
2
3
4
undef
undef
undef
5
6
7
More detailed description ot 3-argument form of the $list() function can be found in the MiniM Language Guide, see descriptions of second and thitd arguments.

Eugene Karataev
support@minimdb.com


Copyright (C) 2017 Eugene Karataev
Emails: Info Tech Support