File: read-array.2gg

package info (click to toggle)
golf 601.4.41-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,824 kB
  • sloc: ansic: 20,020; sh: 1,171; makefile: 292
file content (54 lines) | stat: -rw-r--r-- 1,817 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
.TH GOLF 2gg $VERSION $DATE Development Tools
.SH NAME
read-array \-  (array)
.SH PURPOSE
Get data from an array.

.SH SYNTAX

.RS 4
.EX

read-array <array> \\
    key <key> \\
    value <value> \\
    [ delete [ <delete> ] ] 

.EE
.RE

.SH DESCRIPTION
read-array will obtain an element from <array> (that was created with \fBnew-array\fP); an element obtained is <value> (in "value" clause) based on a number <key> (in "key" clause). <key> is a number from 0 up to (excluding) the currently allocated array size. The type of <value> is determined when <array> is created (see "type" clause), and can be either a string, number or a boolean.

You can also delete an element from the array by using "delete" clause - the <value> is still obtained though it is no longer in the array. The array element is deleted if "delete" clause is used without boolean variable <delete>, or if <delete> evaluates to true. "Deleting" means that if string store would be set to an empty string, a number would be set to 0, and a boolean would be set to false.

Note that array may be allocated beyond the highest index of an element written to it; reading from such elements that have never been written to will produce an empty string, a number 0 or a boolean false value (depending on the type of array).

.SH EXAMPLES
In this example, a new array is created, a value is written to it, and then the value is obtained and the element deleted; return status is checked:

.RS 4
.EX

// Create new array
new-array arr type string

// Write to array
write-array arr key 500 value "some data"

// Read from array
read-array arr key 500 value res status st delete
@Deleted value is <<print-out res>>

.EE
.RE

.SH SEE ALSO
 Array

\fBnew-array\fP  
\fBpurge-array\fP  
\fBread-array\fP  
\fBwrite-array\fP   
See all 
\fBdocumentation\fP