| Transactions between Variables

Prev Next

Introduction

Different from transactions without assignment operators, the | assignment operator in front of the transaction symbol will assume the following rules focussing on overlaying data from the source variable in the destination variable:

  • Transactions can be carried out on base variables as well as member variables.
  • If the destination variable does not yet exist, then it will be created as simple variable containing void value before the transaction begins. However, the source variable on the right-hand side must exist.
  • The existing setup of structure and array members and sub-members in the destination variable may be extended:
    • Further arrays and/or structures may be added.
    • Additional members may be added to existing arrays and/or structures.
    • Destination memebers for which equivalent source members are existing will be overwritten.
  • Where possible, all structure and array members and sub-members of the source variable will be included in the transaction.
  • The base variable of the specified destination will be overwritten if the ^ suffix is not used.



Following actions are applied on the destination variables using this assignment operator:

Destination Source Description
Simple or zero members Simple or zero members The value of the base variable will be transferred as long no ^ suffix is specified.
Simple or zero members Array Base variable: See above. The array (including sub-members) will be transferred.
Simple or zero members Structure Base variable: See above. The structure (including sub-members) will be transferred.
Structure Simple or zero members Base variable: See above.
Structure Array Base variable: See above. The array members will be renamed to structure members where the member names are 8-digit text representations of the index number, e.g. '00000000', '00000001', etc. After this, same rules as for structures described below apply.
Structure Structure Base variable: See above. The structure (including sub-members) will be transferred. - Existing members will be overwritten
- Additional members may be added
- Additional arrays and/or structures may be added
Array Simple or zero members Base variable: See above.
Array Array Base variable: See above. The array will be copied. - If the destination has more members than the source, then the excess destination members remain unaffected.
- If the destination has fewer members than the source, then the array will be extended in order to transfer all members.
Array Structure Base variable: See above. The members for which corresponding member positions are already existing in the destination variable will also be transferred. The existing array members will be replaced by structure members from the source variable, sorted in alphabetic order by member names.
- If the destination has more members than the source, then the excess destination members remain unaffected.
- If the destination has fewer members than the source, then the array will be extended in order to transfer all members.

Copy Transaction Example
  structure( animals1[], { mammal, bird, fish }, { dog, owl, eel} );
  structure( animals1[mammal], { carnivore, herbivore }, { bear, deer } );

  structure( animals2[], { mammal, fish, reptile }, { cat, trout, turtle } );
  structure( animals2[mammal], { carnivore, omnivores }, { lynx, skunk } );

  animals1[] |<== animals2[];  // animals1 contains overwritten fish, reptile and all mammal sub-members
  see(animals1[]);
animals1[]              [Void]                     (void,full access)
bird                    owl                        (softquoted string,full access)
fish                    trout                      (softquoted string,full access)
mammal                  cat                        (softquoted string,full access)
  carnivore             lynx                       (softquoted string,full access)
  herbivore             deer                       (softquoted string,full access)
  omnivores             skunk                      (softquoted string,full access)
reptile                 turtle                     (softquoted string,full access)

Try it yourself: Open LAN_Features_OR_Transactions_between_variables.b4p in B4P_Examples.zip. Decompress before use.
Copy Transaction Example among Structures and Arrays
  structure( animals1[], { mammal, bird, fish }, { dog, owl, eel} );
  structure( animals1[mammal], { herbivore, carnivore }, { deer, bear } );

  structure( animals2[], { mammal, fish, reptile }, { cat, trout, turtle } );
  array( animals2[mammal], { lynx, skunk, shark, pig } );

  animals2[] |<== animals1[];  // Note: bear, then deer replace lynx and skunk
  animals1[] |<== animals2[];

  see(animals2[]); // Array with 4 elements
  see(animals1[]); // Addition of beer, dear, shark and pig
animals2[]              [Void]                     (void,full access)
bird                    owl                        (softquoted string,full access)
fish                    eel                        (softquoted string,full access)
mammal                  dog                        (softquoted string,full access)
  Array [   0]          bear                       (softquoted string,full access)
  Array [   1]          deer                       (softquoted string,full access)
  Array [   2]          shark                      (softquoted string,full access)
  Array [   3]          pig                        (softquoted string,full access)
reptile                 turtle                     (softquoted string,full access)

animals1[]              [Void]                     (void,full access)
bird                    owl                        (softquoted string,full access)
fish                    eel                        (softquoted string,full access)
mammal                  dog                        (softquoted string,full access)
  00000000              bear                       (softquoted string,full access)
  00000001              deer                       (softquoted string,full access)
  00000002              shark                      (softquoted string,full access)
  00000003              pig                        (softquoted string,full access)
  carnivore             bear                       (softquoted string,full access)
  herbivore             deer                       (softquoted string,full access)
reptile                 turtle                     (softquoted string,full access)

Try it yourself: Open LAN_Features_OR_Transactions_between_variables_01.b4p in B4P_Examples.zip. Decompress before use.
Move Transaction Example
  structure( animals1[], { mammal, bird, fish }, { dog, owl, eel} );
  structure( animals1[mammal], { carnivore, herbivore }, { bear, deer } );

  structure( animals2[], { mammal, fish, reptile }, { cat, trout, turtle } );
  structure( animals2[mammal], { carnivore, omnivores }, { lynx, skunk } );

  animals1[mammal] |<<= animals2[mammal];
  // Lynx replaces bear, skunk added, turtle added

  see(animals1[]); // omnivore added, carnivore overwritten
  see(animals2[]); // no more mammal subtypes (...vores)
animals1[]              [Void]                     (void,full access)
bird                    owl                        (softquoted string,full access)
fish                    eel                        (softquoted string,full access)
mammal                  cat                        (softquoted string,full access)
  carnivore             lynx                       (softquoted string,full access)
  herbivore             deer                       (softquoted string,full access)
  omnivores             skunk                      (softquoted string,full access)

animals2[]              [Void]                     (void,full access)
fish                    trout                      (softquoted string,full access)
reptile                 turtle                     (softquoted string,full access)

Try it yourself: Open LAN_Features_OR_Transactions_between_variables_02.b4p in B4P_Examples.zip. Decompress before use.
Swap Transaction Example
  structure( animals1[], { mammal, bird, fish }, { dog, owl, eel} );
  structure( animals1[mammal], { carnivore, herbivore }, { bear, deer } );

  structure( animals2[], { mammal, fish, reptile }, { cat, trout, turtle } );
  structure( animals2[mammal], { carnivore, omnivores }, { lynx, skunk } );

  animals1[] |<=> animals2[];

  see(animals1[]); // trout and eel; and dog and cat are exchanged, owl and turtle duplicated
  see(animals2[]);
animals1[]              [Void]                     (void,full access)
bird                    owl                        (softquoted string,full access)
fish                    trout                      (softquoted string,full access)
mammal                  cat                        (softquoted string,full access)
  carnivore             lynx                       (softquoted string,full access)
  herbivore             deer                       (softquoted string,full access)
  omnivores             skunk                      (softquoted string,full access)
reptile                 turtle                     (softquoted string,full access)

animals2[]              [Void]                     (void,full access)
bird                    owl                        (softquoted string,full access)
fish                    eel                        (softquoted string,full access)
mammal                  dog                        (softquoted string,full access)
  carnivore             bear                       (softquoted string,full access)
  herbivore             deer                       (softquoted string,full access)
  omnivores             skunk                      (softquoted string,full access)
reptile                 turtle                     (softquoted string,full access)

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