Structures
Structures allow a single value to contain multiple named FISH variables. This is a programming data structure that can be used to compartmentalize FISH variables.
See the Structure Utilities for available methods.
A structure may be defined either with the fish structure
command, or with the struct or structure statement as the first thing on a line of FISH input.
An instance of a structure may be created anywhere in an expression by using the struct or structure keyword, followed by the name of the structure and optionally values to initialize structure members as arguments. If uninitialized, structure members have the default FISH value of 0.
Structure members can contain any valid FISH values, including lists or other structures.
Structure members can be accessed using the accessor -> operator followed by the member name. Structure member access is much more efficient than in previous versions of FISH, only slightly slower than direct variable access.
Structure types can be compared against each other with ==, <, > etc. If the structures are of the same type name then each member is compared in order.
The example below illustrates the use of structures.
fish structure fred(one,two,three) ;; Define structure type fred
;; With three members:
;; 'one', 'two', 'three'
fish define test
struct george(val1,val2,val3) ;; Define structure type george
;; with three members:
;; 'val1', 'val2', 'val3'
fred = struct george(1,2,3) ;; Create and initialize a george struct
mary = struct fred ;; Create fred struct
test = fred->val1
mary->two = 'monkey'
end
[test]
As with most aggregate types, when the value is listed it will simply indicate that it is of type Structure and the structure name. To see the contents of the structure use the fish list contents
command.
Was this helpful? ... | FLAC3D © 2019, Itasca | Updated: Feb 25, 2024 |