delete members

Prev Next

Function Names

delete members

Description

This function removes eiteher all member variables (if only 1 parameter, namely the variable, is provided), or a selection of members if a member name (for structures) or index value (for arrays) is specified, followed by an optional variable to specify the number of members to be deleted, beginnig with the specified one.

Attention: If the function call is executed in a local varaible contect (e.g inside a user-defined fuction or a B4P program called by another B4P program using start() or include(), then attempting to delete a non-local variable asserts an exception. You can circumvent this by deleting the global variable in a global context provided with the global() function.
example: global ( ) delete ( a global variable [ ] );

Call as: procedure

Restrictions

Indirect parameter passing is disabled

Parameter count

Min. 1

Parameters

No.TypeDescription
1
code
variable
:string
Variable name

The affected variable will be deleted resp. their members deleted.

Opt. 2
input
numeral Starting array index

Appicable to arrays and structures. The index must refer to an existing member in the array. Negative indexing is supported, e.g. -1 refers to the last member

Default value: All members will be deleted if the 2nd function parameter is not provided
Alt. 2
input
numeral Starting member name

Appicable structures only. It must match with an existing member name.

Default value: All members will be deleted if the 2nd function parameter is not provided
Opt. 3
input
numeral Ending array index

Appicable to arrays and structures. The index must refer to an existing member in the array. Negative indexing is supported, e.g. -1 refers to the last member. Note that the ending member must lie after the starting member, otherwise nothing will be deleted.

Default value: Only one member will be deleted if the 3rd parameter is not provided
Alt. 3
input
numeral Ending member name

Appicable structures only. It must match with an existing member name and alphabetically after the starting member name. Otherwise, nothing will be deleted.

Default value: Only one member will be deleted if the 3rd parameter is not provided

Exceptions

Variable is protected
Attempting to delete global variable in local context
Attempting to delete system variables

Examples


       array( a[], { 0, 11, 22, 33, 44, 55, 66, 77, 88, 99 } );
       a[] = This is the base variable;

       delete members( a[], 2, 4 );    // Delete 22, 33, 44
       delete members( a[], -1 );      // Delete 99

       see(a[]);

       echo("Delete all remaining members");
       delete members( a[] );
       see(a[]);


       structure( a[], { Cat,   Dog,  Bird,  { Parrot, Parakeet  }, Rat,  Mouse, Elephant, Zebra },
                       { Katze, Hund, Vogel, { Papagei, Sittich  }, Ratte, Maus, Elefant,  Zebra } );

       delete members( a[], Bird, Dog );   // Bird (incl. Parrot, Parakeet), Cat, Dog
       delete members( a[], Rat);          // Delete Rat
       delete members( a[], -2);           // Delete Mouse

       see(a[]);                       // Elephant, Zebra

Output

a[]                     This is the base variable    (softquoted string,full access)
Array [   0]            0  "0"                     (numeral,full access)
Array [   1]            11  "11"                   (numeral,full access)
Array [   2]            55  "55"                   (numeral,full access)
Array [   3]            66  "66"                   (numeral,full access)
Array [   4]            77  "77"                   (numeral,full access)
Array [   5]            88  "88"                   (numeral,full access)

Delete all remaining members
a[]                     This is the base variable    (softquoted string,full access)

a[]                     This is the base variable    (softquoted string,full access)
Elephant                Elefant                    (softquoted string,full access)
Zebra                   Zebra                      (softquoted string,full access)

Try it yourself: Open LIB_Function_delete_members.b4p in B4P_Examples.zip. Decompress before use.

See also

delete
release
insert members