middle ... (parameter set function)

Prev Next

Function Names

middle , middle include , middle until , middle until include

Description

This function extracts a middle part of the parameter set either with two element position numbers or matching elements or a combination of both.

Call as: function

Restrictions

Indirect parameter passing is disabled

Parameter count

Min 3

Parameters

No.TypeDescription
1
input
parameter set input parameter set

Attention: If 1st parameter is not a parameter set, please refer to middle [string function] instead.

2
input
numeral starting element position

Positive: Begin with specified element (0 = 1st element, 1 = 2nd element, etc.)
Larger than number of elements: empty set
Negative: Starting position counted from right to left, e.g. -1 = last element
Smaller than minus number of parameter set elements in the parameter set: Begins with 1st element
The function name ending '... include' will be ignored.

Alt. 2
input
parameter set starting matching elements

Function middle ...: Middle part of the parameter set begins after the matching element.
Function middle include ...: Middle part of the parameter set begins including the matching element. Empty parameter sets are interprested as per se found.

If this function parameter contains 2 or more elements, then the set will be compared with all elements and the first match with any of these elements will apply.
Function name ending ... last match: Looks for the last matching element in the parameter set and not the first one.

3
input
numeral element count or ending element position

For function names middle until, this parameter contains the ending element position. Negative numbers count from right to left: -1 = last parameter set element included, -2 = 2nd last element included.
Element positions before the starting position of found matching element will return empty sets.
For function names not containing until, this parameter contains the element count. 0 and negative numbers return empty sets.

The function name ending '... include' will be ignored.

Alt. 3
input
parameter set ending matching elements

Function outside ...: 2nd part of the parameter set begins including the ending matching elemetn.
Function outside exclude ...: 2nd part of the parameter set begins after the ending matching element.
Empty parameter sets means no further matches and the full original parameter set is returned.

Attention: The function names ending outside until combined with matching elements provided will assert errors.

If this function parameter contains 2 or more elements, then the set will be compared with all elements and the first match with any of these elements will apply.
Function name ending ... last match: Looks for the last matching element in the parameter set and not the first one. Empty parameter sets are interprested as per se found.

Opt. 4+
io
parameter set follower

Other parameter sets in addition to the one provided as the first function parameter can be extracted in the same same way. Add any number of additional parameter set variables. They will be manipulated at the exact same positions as the returned value.

Return value

TypeDescription
parameter set Extracted subset

Examples

      set[] = { the, taste, of, the, 12, coffees, '!' };

      echo( middle( set[], 4,  2 ), " / ", middle until( set[], 1, 5 ) );
      echo( middle( set[], -3, 2 ), " / ",  middle until( set[], -6, -2 ) );
      echo;
      echo( middle( set[],  99, 3 ), " / ",  middle until ( set[],  99, 3 ) ); // empty sets
      echo( middle( set[], -99, 3 ), " / ",  middle until ( set[], -99, 3 ) ); // the taste of / ... the
      echo;
      echo( middle( set[], {taste}, 4 ), " / ", middle include( set[], {taste}, 4 ) ); // 4 elements in both cases
      echo( middle until( set[], {taste}, -2 ), " / ", middle until include( set[], {taste}, -2 ) );
      echo( middle ( set[], {taste}, {coffees} ), " / ", middle include( set[], {taste}, {coffees} ) );

      echo( middle ( set[], {}, {coffees} ), " / ", middle include( set[], {taste}, {} ) );
      echo( middle ( {}, {}, {coffees} ), " / ", middle include( {}, {taste}, {} ) ); // empty sets
      echo;
      echo( "Demonstrate the follower feature: ");

      set2[] = { A, fragrance, coming, from, 120, espressos, '!' };
      set3[] = { Der, Geschmack, kommt, von, 120, Tassen Kaffee, '!' };

      echo( "Extraction 1: ", middle( set[], {of}, 3, set2[], set3[] ) );
      echo( "Extraction 2: ", set2[] );
      echo( "Extraction 3: ", set3[] );

Output

{12,'coffees'} / {'taste','of','the',12,'coffees'}
{12,'coffees'} / {'taste','of','the',12,'coffees'}

{} / {}
{'the','taste','of'} / {'the','taste','of','the'}

{'of','the',12,'coffees'} / {'taste','of','the',12}
{'of','the',12,'coffees'} / {'taste','of','the',12,'coffees'}
{'of','the',12} / {'taste','of','the',12,'coffees'}
{'the','taste','of','the',12} / {}
{} / {}

Demonstrate the follower feature:
Extraction 1: {'the',12,'coffees'}
Extraction 2: {'from',120,'espressos'}
Extraction 3: {'von',120,'Tassen Kaffee'}
Try it yourself: Open LIB_Function_middle_.b4p in B4P_Examples.zip. Decompress before use.

See also

left [parameter set function]
right [parameter set function]
outside [parameter set function]
middle [string function]