Previous Page Contents

listlib::sublist -- search sublists

Introduction

listlib::sublist(list1, list2) determines, whether the list list1 contains another list list2.

Call(s)

listlib::sublist(list1, list2 <, index> <, option>)

Parameters

list1, list2 - MuPAD list
index - integer, that determines the first search position
option - option Consecutive

Options

Consecutive - determines that the sublist list2 is containing coherent in list1

Returns

the position of the first element of the containing sublist or zero

Related Functions

contains, op

Details

Example 1

The sublist is a part of the list, but not in one piece:

>> listlib::sublist([1, 2, 3, 4, 5, 6, 7, 8], [2, 3, 5, 6])
                                     2
>> listlib::sublist([1, 2, 3, 4, 5, 6, 7, 8], [2, 3, 5, 6], Consecutive)
                                     0

The list contains the sublist, coherent and incoherent:

>> listlib::sublist([1, 2, 3, 4, 5, 1, 3, 5], [1, 3, 5])
                                     1
>> listlib::sublist([1, 2, 3, 4, 5, 1, 3, 5], [1, 3, 5], Consecutive)
                                     6

Example 2

Find the last occurence of the sublist inside of the list:

>> POS:= 0:
   while listlib::sublist([1, 2, 3, 1, 3, 1, 2, 3], [1, 2, 3], POS + 1) > 0 do
     POS:= listlib::sublist([1, 2, 3, 1, 3, 1, 2, 3], [1, 2, 3], POS + 1)
   end_while:
   POS
                                     6
>> delete POS:

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000