File: statements.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 (193 lines) | stat: -rw-r--r-- 5,741 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
.TH GOLF 2gg $VERSION $DATE Development Tools
.SH NAME
statements \- Golf documentation (language)
.SH DESCRIPTION

.LP
.B STATEMENTS
.LP

Golf statements generally have three components separated by space(s):

.RS 4
\[bu]    
a name,

.RE

.RS 4
\[bu]    
an object,

.RE

.RS 4
\[bu]    
clauses.
.RE

A statement starts with a name, which designates its main purpose. 

An object denotes what is referenced by a statement. 

Each clause that follows consist of a clause name followed either with no arguments, or with one or more arguments. A clause may have subclauses immediately afterwards, which follow the same structure. Most clauses are separated by space(s), however some (like "=" or "@") may not need space(s) before any data; the statement's documentation would clearly specify this.

An object must immediately follow the statement's name, while clauses may be specified in any order.

For example, in the following Golf code:

.RS 4
.EX

encrypt-data orig_data input-length 6 password "mypass" salt newsalt to res binary

.EE
.RE

encrypt-data is the statement's name, and "orig_data" is its object. The clauses are:

.RS 4
\[bu]    
input-length 6

.RE

.RS 4
\[bu]    
password "mypass"

.RE

.RS 4
\[bu]    
salt newsalt

.RE

.RS 4
\[bu]    
to res 

.RE

.RS 4
\[bu]    
binary
.RE

The clauses can be in any order, so the above can be restated as:

.RS 4
.EX

encrypt-data orig_data to res password "mypass" salt newsalt binary input-length 6

.EE
.RE

Golf documentation provides a concise BNF-like notation of how each statement works, which in case of \fBencrypt-data\fP is (backslash simply allows continuing to multiple lines):

.RS 4
.EX

encrypt-data <data> to <result> \\
    [ input-length <input length> ] \\
    [ binary [ <binary> ] ] \\
    ( password <password> \\
        [ salt <salt> [ salt-length <salt length> ] ] \\
        [ iterations <iterations> ] \\
        [ cipher <cipher algorithm> ] \\
        [ digest <digest algorithm> ]
        [ cache ]
        [ clear-cache <clear cache> ) \\
    [ init-vector <init vector> ]

.EE
.RE

Note the color scheme: clauses with input data are in blue, and with output data in green.

Optional clauses are enclosed with angle brackets (i.e between "[" and "]").

Arguments (in general variables and constants) are stated between "<" and ">". 

If only one of a number of clauses may appear, such clauses are separated by "|".

A group of clauses that cannot be separated, or to remove ambiguity, are enclosed with "(" and ")". 

Keywords (other than statement names such as encrypt-data above) are generally specific to each statement. So, keyword "salt", for example, has meaning only within encrypt-data and a few other related statements. In order to have the freedom to choose your variable names, you can simply surround them in parenthesis (i.e. "(" and ")") and use any names you want, even keywords, for example:

.RS 4
.EX

set-string password = "some password"
set-string salt = "0123456789012345"
encrypt-data "some data" password (password) salt (salt) to enc_data
print-out enc_data

.EE
.RE

In this example, keywords "password" and "salt" are used as variable names as well.

Note that while you can use tab characters at the beginning of the line (such as for indentation), as well as in string literals, do not use tabs in Golf statements otherwise as they are not supported for lack of readability - use plain spaces.

.LP
.B SPLITTING STATEMENT INTO MULTIPLE LINES, SPACE TRIMMING
.LP

To split a statement into multiple lines (including string continuations), use a backslash (\e), for instance:

.RS 4
.EX

encrypt-data orig_data input-length 6 \\
    password "my\\
    pass" salt \\
    newsalt to res binary 

.EE
.RE

Note that all statements are always left-trimmed for whitespace. Thus the resulting string literal in the above example is "mypass", and not "my   pass", as the whitespaces prior to line starting with "pass" are trimmed first. Also, all statements are right-trimmed for white space, except if backslash is used at the end, in which case any spaces prior to backslash are conserved. For that reason, in the above example there is a space prior to a backslash where clauses need to be separated.

Note that \fBbegin-handler\fP statement cannot be split with backsplash, i.e. it must always be on a single line for readability.

.LP
.B COMMENTS
.LP

You can use both C style (i.e. /* ... */) and C++ style (i.e. //) comments with Golf statements, including within statements (with the exception of /*..*/ before statement name for readability), for example:

.RS 4
.EX

run-query @db = \\
    "select firstName, lastName from employee where yearOfHire>='%s'" \\
    output /* comment within */ firstName, lastName : "2015" // other comment

.EE
.RE


.LP
.B ERROR HANDLING
.LP

A statement that fails for reasons that are generally irrecoverable will \fBerror out\fP, for example out of memory or disk space, bad input parameters etc. 

Golf philosophy is to minimize the need to check for such conditions by preventing the program from continuing. This is preferable, as forgetting to check usually results in unforeseen bugs and safety issues, and the program should have stopped anyway. 

Errors that are correctable programmatically are reported and you can check them, for example when opening a file that may or may not exist.

Overall, the goal is to stop execution when necessary and to offer the ability to handle an issue when warranted, in order to increase run-time safety and provide instant clues about conditions that must be corrected.
.SH SEE ALSO
 Language

\fBinline-code\fP  
\fBstatements\fP  
\fBsyntax-highlighting\fP  
\fBunused-var\fP  
\fBvariable-scope\fP   
See all 
\fBdocumentation\fP