Original Author Paul Laughton, 2011
Page 48
De Re BASIC!
arrays. Bundles can also be contained in other bundles. This means that the combination of lists and
bundles can be used to create arbitrarily complex data structures.
After a bundle is created, keys and values can be added to the bundle using the Bundle.put command.
Those values can be retrieved using the keys in the Bundle.get command. There are other bundle
commands to facilitate the use of bundles.
Bundle Auto-Create
Every bundle command except Bundle.create has a parameter, the <pointer_nexp>, which can point to
a bundle. If the expression value points to a bundle, the existing bundle is used. If it does not, and the
expression consists only of a single numeric variable, then a new, empty bundle is created, and the
variable value is set to point to the new bundle.
That may seem complex, but it isn't, really. If there is a bundle, use it. If there is not, try to create a new
one but BASIC! can't create a new bundle if you don't give it a variable name. BASIC! uses the variable
to tell you how to find the new bundle.
BUNDLE.PUT b,"key1", 1.2
% try to put a value in the bundle pointed to by b
BUNDLE.PUT 10, key2$, value2
% try to put a value in the 10th bundle created
BUNDLE.REMOVE c + d, key$[3],
% try to remove a key/value pair from a bundle
% pointed to by c + d
In the first example, if the value of b points to a bundle, the Bundle.put puts "key1" and the value 1.2
into that bundle. If b is a new variable, its value is 0.0, so it does not point to a bundle. In that case, the
Bundle.put creates a new bundle, puts "key1" and the value 1.2 into the new bundle, and sets b to
point to the new bundle.
In the second example, if there are at least ten bundles, then the Bundle.put tries to put the key named
in the variable key2$ and the value of the variable value2 into bundle 10. If there is no bundle 10, then
the command does nothing. It can't create a new variable because you did not provide a variable to
return the bundle pointer.
In the third example, the bundle pointer is the value of the expression c + d. If there is no such bundle,
the command does nothing. To create a new bundle, the bundle pointer expression must be a single
numeric variable.
Bundle Commands
Bundle.create <pointer_nvar>
A new, empty bundle is created. The bundle pointer is returned in <pointer_nvar>.
Example:
BUNDLE.CREATE bptr