Scol standard library package  0.3.1
Common and usefull functions for all Scol applications
Functions
The list API.

Functions

 std_lApplyFunc (list, f, x)
 apply a function to a list More...
 
 std_lCat (p, q)
 Concat two list to one. More...
 
 std_lDifference (lA, lB)
 Difference between two lists. More...
 
 std_lDifferenceSym (lA, lB)
 Symetric difference between two lists (xor) More...
 
 std_lDisjoint (lA, lB)
 Returns if a list is disjoint in another one (they have no element in common). More...
 
 std_lDivide (x, p, r1, r2, f)
 Divide list. More...
 
 std_lDivideList (item, items, sub1, sub2, func)
 Divide a list in two sub lists. More...
 
 std_lDivideString (x, p, r1, r2, f)
 Divide string list. More...
 
 std_lEltBigger (a, b)
 Conivience function to compare two elements. More...
 
 std_lEltCmp (a, b)
 Conivience function to compare two elements (string excepted) More...
 
 std_lEltNCmp (a, b)
 Conivience function to compare two elements (string excepted) More...
 
 std_lEltPos (list, e)
 Return the position of an element. More...
 
 std_lEltPosFunc (list, f, e)
 Return the position of an element. More...
 
 std_lEltPosStr (list, e)
 Return the position of a string element case sensitive. More...
 
 std_lEltPosStri (list, e)
 Return the position of a string element case insensitive. More...
 
 std_lEltSmaller (a, b)
 Conivience function to compare two elements. More...
 
 std_lEquals (lA, lB, f)
 Return if two lists are equals (same size, same items, same order) More...
 
 std_lExtractList (list, e, func)
 Extract a list in two sub list. More...
 
 std_lInclude (lA, lB)
 Returns if a list is included in another one. More...
 
 std_lIntersection (lA, lB)
 Intersection between two lists (and) More...
 
 std_lIsInList (list, e)
 Check if a value is in a given list. More...
 
 std_lIsInListFunc (list, f, e)
 Check if a value is in a given list. More...
 
 std_lQuickSort (list, func)
 Sort a list using an external function. More...
 
 std_lQuicksort (l, f)
 
 std_lQuicksortString (l, f)
 Sort a string list. More...
 
 std_lRemoveElt (list, e)
 Remove an element in a list. More...
 
 std_lRemoveFunc (list, func, e)
 Remove an element in a list by a function. More...
 
 std_lRemoveStr (list, e)
 Remove an string in a list. Case-sensitive. More...
 
 std_lRemoveStri (list, e)
 Remove an string in a list. Case-insensitive. More...
 
 std_lReplaceElement (lSrc, oldElt, newElt)
 Replace an element by other one. More...
 
 std_lReplaceElementStr (lSrc, oldS, newS)
 Replace an string by other one Case sensitive. More...
 
 std_lReplaceElementStri (lSrc, oldS, newS)
 Replace an string by other one Case insensitive. More...
 
 std_lReverse (list)
 Reverse a list (perform a mirror) More...
 
 std_lSetUnique (lSrc)
 Remove all supplemental elements. The list will have unique elements only. More...
 
 std_lSetUniqueEx (lSrc, func)
 Remove all supplemental elements. The list will have unique elements only. More...
 
 std_lSortList (l, f)
 Sort a list. More...
 
 std_lSplit (l, pos)
 Split a list in two list at given position. More...
 
 std_lStriIsInList (list, e)
 Check if a string is in a given string list case insensitive. More...
 
 std_lStrIsInList (list, e)
 Check if a string is in a given string list case sensitive. More...
 
 std_lSub (list, start, end)
 Extract a list between to indices. More...
 
 std_lUnion (lA, lB)
 Union between two lists (or) More...
 

Detailed Description

Package to load : lib/std/list.pkg

Function Documentation

std_lCat ( ,
 
)

Concat two list to one.

Prototype: fun [[u0 r1] [u0 r1]] [u0 r1]

Parameters
[u0r1] : first list to concat
[u0r1] : second list to concat
Returns
[u0 r1] : concatened list
std_lExtractList ( list  ,
,
func   
)

Extract a list in two sub list.

Prototype: fun [[u0 r1] u0 fun [u0 u0] I] [u0 r1]

Parameters
[u0r1] : any list
u0: the seperator (an element of the list)
fun[u0 u0] I : function to call to test
Returns
[[u0 r1] [u0 r1]] : two sub lists
std_lSortList ( ,
 
)

Sort a list.

Prototype: fun [[u0 r1] fun [u0 u0] I] [u0 r1]

Parameters
[u0r1] : list to sort
fun[u0 u0] I : function to test
Returns
[u0 r1] : the sorted list
std_lDivideList ( item  ,
items  ,
sub1  ,
sub2  ,
func   
)

Divide a list in two sub lists.

Prototype: fun [u0 [u0 r1] [u0 r1] [u0 r1] fun [u0 u0] I] [u0 r1]

Parameters
u0: could be the first element of a list
[u0r1] : should be the next (tail) of a list
[u0r1] : the first sub list (could be nil when this function is called)
[u0r1] : the second sub list (could be nil when this function is called)
fun[u0 u0] I : a testing function to call with each element. It should return 0 if two elements are equals or a positive / negative integer depending on the order.
Returns
[[u0 r1] [u0 r1]] : a tuple with the two sub list
std_lQuickSort ( list  ,
func   
)

Sort a list using an external function.

Prototype: fun [[u0 r1] fun [u0 u0] I] [u0 r1]

Parameters
[u0r1] : list to sort
fun[u0 u0] I : function for sort test
Returns
[u0 r1] : sorted list
std_lReverse ( list  )

Reverse a list (perform a mirror)

Prototype: fun [[u0 r1]] I

Parameters
[u0r1] : list to revert
Returns
[u0 r1] : reversed list
std_lSub ( list  ,
start  ,
end   
)

Extract a list between to indices.

Prototype: fun [[u0 rI] I I] [u0 r1]

Parameters
[u0r1] : a list
I: the starting position. If nil, the list is fully returned.
I: the ending position. If nil, the list is fully returned.
Returns
I : the sub-list
std_lSplit ( ,
pos   
)

Split a list in two list at given position.

Prototype: fun [[u0 r1] I] [[u0 r1] [u0 r1]]

Parameters
[u0r1] : list to split
I: position (start at 0), use a negative value for a position from the list end
Returns
[[u0 r1] [u0 r1]] : splited list (two sub lists)
std_lDivide ( ,
,
r1  ,
r2  ,
 
)

Divide list.

Prototype: fun [u0 [u0 r1] [u0 r1] [u0 r1] fun [u0 u0] I] [u0 r1]

Private

Returns
[[u0 r1] [u0 r1]]
std_lDivideString ( ,
,
r1  ,
r2  ,
 
)

Divide string list.

Prototype: fun [[S r1] [[S r1] r1] [[S r1] r1] [[S r1] r1] fun [[S r1] [S r1]] I] [[S r1] r1]

Private

Returns
[[[S r1] r1] [[S r1] r1]]
std_lQuicksort ( ,
 
)

brief Sort a list

Prototype: fun [[u0 r1] fun [u0 u0] I] [u0 r1]

Parameters
[u0r1] : list to sort
fun[u0 u0] I : function for sort test
Returns
[u0 r1] : sorted list
std_lQuicksortString ( ,
 
)

Sort a string list.

Prototype: fun [[S r1] fun [S S] I] [S r1]

Parameters
[Sr1] : list to sort
fun[S S] I : function for sort test
Returns
[S r1] : sorted list
std_lApplyFunc ( list  ,
,
 
)

apply a function to a list

Prototype: fun [[u0 r1] fun [u0 u1] u0 u1] [u0 r1]

Parameters
[u0r1] : a list
fun[u0 u1] u0 : the function to call for each list element
u1: a user parameter
Returns
[u0 r1] : the new list
std_lRemoveFunc ( list  ,
func  ,
 
)

Remove an element in a list by a function.

Prototype: fun [[u0 r1] fun [u0 u0] I u0] [u0 r1]

Parameters
[u0r1] : a list
u0: the list element to remove
Returns
[u0 r1] : the list without the element
std_lRemoveElt ( list  ,
 
)

Remove an element in a list.

Prototype: fun [[u0 r1] u0] [u0 r1]

Parameters
[u0r1] : a list
u0: the list element to remove
Returns
[u0 r1] : the list without the element
std_lRemoveStr ( list  ,
 
)

Remove an string in a list. Case-sensitive.

Prototype: fun [[S r1] S] [S r1]

Parameters
[Sr1] : a list
S: the list element to remove
Returns
[S r1] : the same list without the element
std_lRemoveStri ( list  ,
 
)

Remove an string in a list. Case-insensitive.

Prototype: fun [[S r1] S] [S r1]

Parameters
[Sr1] : a list
S: the list element to remove
Returns
[S r1] : the same list without the element
std_lEltPos ( list  ,
 
)

Return the position of an element.

Prototype: fun [[u0 r1] u0] I

Parameters
[u0r1] : a list
u0: an element to found
Returns
I : its position or nil if not found
std_lEltPosStr ( list  ,
 
)

Return the position of a string element case sensitive.

Prototype: fun [[S r1] S] I

Parameters
[Sr1] : a list
S: an element to found
Returns
I : its position or nil if not found
std_lEltPosStri ( list  ,
 
)

Return the position of a string element case insensitive.

Prototype: fun [[S r1] S] I

Parameters
[Sr1] : a list
S: an element to found
Returns
I : its position or nil if not found
std_lEltPosFunc ( list  ,
,
 
)

Return the position of an element.

Prototype: fun [[u0 r1] fun [u0 u0] I u0] I

Parameters
[u0r1] : a list
fun[u0 u0] I : a function to compare, should return 1 if ok
u0: an element to found
Returns
I : its position or nil if not found
std_lIsInList ( list  ,
 
)

Check if a value is in a given list.

Prototype: fun [[u0 r1] u0] I

Parameters
[u0r1] : a list
u0: an element to found
Returns
I : 0 if found or 1 if not found
std_lIsInListFunc ( list  ,
,
 
)

Check if a value is in a given list.

Prototype: fun [[u0 r1] fun [u0 u0] I u0] I

Parameters
[u0r1] : a list
fun[u0 u0] I : a function to compare, should return 1 if ok
u0: an element to found
Returns
I : 0 if found or 1 if not found
std_lStrIsInList ( list  ,
 
)

Check if a string is in a given string list case sensitive.

Prototype: fun [[S r1] S] I

Parameters
[Sr1] : a list
S: an element to found
Returns
I : 0 if found or 1 if not found
std_lStriIsInList ( list  ,
 
)

Check if a string is in a given string list case insensitive.

Prototype: fun [[S r1] S] I

Parameters
[Sr1] : a list
S: an element to found
Returns
I : 0 if found or 1 if not found
std_lEltCmp ( ,
 
)

Conivience function to compare two elements (string excepted)

Prototype: fun [u0 u0] I

Parameters
u0: an element
u0: another element
Returns
I : 1 if equal
std_lEltNCmp ( ,
 
)

Conivience function to compare two elements (string excepted)

Prototype: fun [u0 u0] I

Parameters
u0: an element
u0: another element
Returns
I : 1 if not equal
std_lEltSmaller ( ,
 
)

Conivience function to compare two elements.

Prototype: fun [u0 u0] I

Parameters
u0: an element, generally an integer
u0: another element, generally another integer
Returns
I : 1 if the first argument is smaller then the second argument
std_lEltBigger ( ,
 
)

Conivience function to compare two elements.

Prototype: fun [u0 u0] I

Parameters
u0: an element, generally an integer
u0: another element, generally another integer
Returns
I : 1 if the first argument is bigger then the second argument
std_lSetUnique ( lSrc  )

Remove all supplemental elements. The list will have unique elements only.

Prototype: fun [[u0 r1]] [u0 r1]

Parameters
[u0r1] : a list
Returns
[u0 r1] : the same list with unique elements only
std_lSetUniqueEx ( lSrc  ,
func   
)

Remove all supplemental elements. The list will have unique elements only.

Prototype: fun [[u0 r1] fun [u0 u0] I] [u0 r1]

Parameters
[u0r1]: a list
fun[u0 u0] I : function to test, at your convenience
Returns
[u0 r1] : the same list with unique elements only
See also
std_lSetUnique
std_lReplaceElement ( lSrc  ,
oldElt  ,
newElt   
)

Replace an element by other one.

Prototype: fun [[u0 r1] u0 u0] [u0 r1]

Parameters
[u0r1] : a list
u0: element to replace
u0: new element
Returns
[u0 r1] : the same list with the replacement
std_lReplaceElementStr ( lSrc  ,
oldS  ,
newS   
)

Replace an string by other one Case sensitive.

Prototype: fun [[S r1] S S] [S r1]

Parameters
[Sr1] : a list
S: a string to replace
S: a new string
Returns
[S r1] : the same list with the replacement
std_lReplaceElementStri ( lSrc  ,
oldS  ,
newS   
)

Replace an string by other one Case insensitive.

Prototype: fun [[S r1] S S] [S r1]

Parameters
[Sr1] : a list
S: a string to replace
S: a new string
Returns
[S r1] : the same list with the replacement
std_lIntersection ( lA  ,
lB   
)

Intersection between two lists (and)

Prototype: fun [[u0 r1] [u0 r1]] [u0 r1]

Parameters
[u0r1] : a first list (ex : 0::2::4::6::nil)
[u0r1] : a second list (ex : 0::3::6::nil)
Returns
[u0 r1]: the intersection (ex : 0::6::nil)
std_lUnion ( lA  ,
lB   
)

Union between two lists (or)

Prototype: fun [[u0 r1] [u0 r1]] [u0 r1]

Parameters
[u0r1] : a first list (ex : 0::2::4::6::nil)
[u0r1] : a second list (ex : 0::3::6::nil)
Returns
[u0 r1]: the union (ex : 0::2::3::4::6::nil)
Remarks
the output list is not sorted.
std_lDifference ( lA  ,
lB   
)

Difference between two lists.

Prototype: fun [[u0 r1] [u0 r1]] [u0 r1]

Parameters
[u0r1] : a first list (ex : 0::2::4::6::nil)
[u0r1] : a second list (ex : 0::3::6::nil)
Returns
[u0 r1]: the difference (ex : 1st - 2nd : 2::4::nil ; 2nd - 1st : 3::nil)
std_lDifferenceSym ( lA  ,
lB   
)

Symetric difference between two lists (xor)

Prototype: fun [[u0 r1] [u0 r1]] [u0 r1]

Parameters
[u0r1] : a first list (ex : 0::2::4::6::nil)
[u0r1] : a second list (ex : 0::3::6::nil)
Returns
[u0 r1]: the sym. diff. (ex : 2::3::4::nil)
std_lInclude ( lA  ,
lB   
)

Returns if a list is included in another one.

Prototype: fun [[u0 r1] [u0 r1]] I

Parameters
[u0r1] : a list to check (ex : 2::4::nil)
[u0r1] : another list (ex : 0::2::4::6::nil)
Returns
I : 1 if the first list is included in the second, else 0 (ex : 1)
std_lDisjoint ( lA  ,
lB   
)

Returns if a list is disjoint in another one (they have no element in common).

Prototype: fun [[u0 r1] [u0 r1]] I

Parameters
[u0r1] : a list to check (ex : 2::4::nil)
[u0r1] : another list (ex : 0::2::4::6::nil)
Returns
I : 1 if yes, else 0 (ex : 0)
std_lEquals ( lA  ,
lB  ,
 
)

Return if two lists are equals (same size, same items, same order)

Prototype: fun [[u0 r1] [u0 r1] fun [u0 u0] I] I

Parameters
[u0r1] : a first list
[u0r1] : a second list
fun[u0 u0] I : a function to compare each first list item with each second list item. It must return 1 if two items are equals.
Returns
I : the result : 1 if equals, 0 else