/* Source code made by iri This code is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. You can do what you want with it */ typeof listA = [I r1];; typeof listB = [I r1];; fun getNelement (list, n)= if list == nil then nil // the list is smaller then n else let list -> [first next] in if n == 0 then first else getNelement next n-1;; // we continue with the next of the current list fun mainGetNelement ()= _showconsole; set listA = [0 [10 [21 [32 [43 [54 [65 [76 nil]]]]]]]]; _fooId getNelement listA 5; // 54 is displayed 0;; fun getSizeList (list, n)= if list == nil then n // we are at the end of the list (= nil) else getSizeList tl list n+1;; // we continue with the next of the current list fun mainSizeList ()= _showconsole; set listA = [0 [10 [21 [32 [43 [54 [65 [76 nil]]]]]]]]; _fooId getSizeList listA 0; // 8 is displayed 0;; fun setNelement (list, position, value)= if list == nil then nil // the list is smaller then n else if position == 0 then [value tl list] // or value :: (tl list), it is the same thing else [hd list setNelement tl list position-1 value];; // we continue with the next of the current list fun mainSetNelement ()= _showconsole; set listA = [0 [10 [21 [32 [43 [54 [65 [76 nil]]]]]]]]; set listA = setNelement listA 5 100; // [0 [10 [21 [32 [43 [100 [65 [76 nil]]]]]]]] _fooIdList listA; 0;; fun getSubList (list, position)= if list == nil then nil // the list is smaller then n else if position == 0 then list else getSubList tl list position-1;; // we continue with the next of the current list fun mainSubList ()= _showconsole; set listA = [0 [10 [21 [32 [43 [54 [65 [76 nil]]]]]]]]; set listA = getSubList listA 5; // [54 [65 [76 nil]]] _fooIdList listA; 0;; fun findAnInteger (list, intToFind, position)= // all types except a string (S) if list == nil then nil // not found else if intToFind == hd list then position else findAnInteger tl list intToFind position+1;; // we continue with the next of the current list fun findAString (list, strToFind, position)= // type string (S) only if list == nil then nil // not found else if (!strcmp strToFind hd list )then position else findAString tl list strToFind position+1;; // we continue with the next of the current list fun mainFind ()= _showconsole; set listA = [0 [10 [21 [32 [43 [54 [65 [76 nil]]]]]]]]; _fooId findAnInteger listA 54 0; // 5 0;; fun cmpLists (listA, listB)= if ((listA == nil) && (listB == nil)) then // lists are ended, we return 1 (true) 1 else if (hd listA) == (hd listB) then // First elements are equals, we continue with the next cmpLists tl listA tl listB else // first elements ae differents, we stop and returns 0 (false) 0;; fun mainCmp ()= _showconsole; set listA = [0 [10 [21 [32 [43 [54 [65 [76 nil]]]]]]]]; set listB = [0 [10 [21 [32 [43 [54 [65 nil]]]]]]]; _fooId cmpLists listA listB; 0;;