Set or String (Func. Param. Type)

Prev Next

Introduction

Various functions accept either sets or strings when expecting one or multiple strings, for example file names as supported by various file functions. The rules are described below Whenever a function expects a function parameter for table columns, the following types are supported and automatically put into sets.

Type Description Example
Quoted strings The content of the entire string is interpreted as one single string value
Empty strings "" are treated as they are.
"Last,First Name" is such an example
Softquoted strings The content of the entire string is interpreted as one single string value,too
Empty strings '' are treated as they are.
'Last,First Name' is such an example
Sets Sets can contain any number of values
Empty sets {} provide zero values.
{ Last Name, First Name, "Value [EUR]", 123 }



The following code example demonstrates this parameter type ruling using a user-defined function. The user-defined function gets all values in form of sets and prints the contents.

       define procedure( demonstrate, { { parameter 1, to set } }, 1, unlimited )
       {
           for (i[] = 1, i[] <= parameter count[], i[]++)
           {
               var name[] = 'parameter ' + str(i[]);
               print( var name[][], "  (", var name[][]{}," items) " );
           }
           echo;
       }

       demonstrate( A, B );
       demonstrate( Hello World,  Hello   World  ); // Both are same
       demonstrate( "A,B", " A, B " ); // Both are different
       demonstrate( 'A,B', ' A , B '); // Both are same
       demonstrate( set('A,B'), set(' A , B ')); // The function 'set' breaks this softquoted string into 2 parts
       demonstrate( "", '', '  ' ); // Blank, empty, empty
       demonstrate( 'Hello World,  Hello   World  ,"   Hello   World   "');
       demonstrate( { Hello   World, '  Hello   World  ',"   Hello   World   "}); // Note the differences

       echo;

       define additional procedure( demonstrate 2, demonstrate,
           { { parameter 1, to set members to string } }, 1, unlimited );
       
       demonstrate   ( { 1, 2, '3' } );
       demonstrate 2 ( { 1, 2, '3' } ); // Note: All numbers are converted to strings
{'A'}  (1 items) {'B'}  (1 items)
{'Hello World'}  (1 items) {'Hello World'}  (1 items)
{'A,B'}  (1 items) {' A, B '}  (1 items)
{'A,B'}  (1 items) {' A , B '}  (1 items)
{'A','B'}  (2 items) {'A','B'}  (2 items)
{''}  (1 items) {''}  (1 items) {'  '}  (1 items)
{'Hello World,  Hello   World  ,"   Hello   World   "'}  (1 items)
{'Hello World','  Hello   World  ','   Hello   World   '}  (3 items)

{1,2,'3'}  (3 items)
{'1','2','3'}  (3 items)
Try it yourself: Open LAN_Features_set_or_string.b4p in B4P_Examples.zip. Decompress before use.