You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: TUTORIAL.md
+65-32Lines changed: 65 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -151,6 +151,7 @@ It won't print out "print[]", but it will print out "echo", because FreakC will
151
151
# Variables
152
152
153
153
## Variables
154
+
### String
154
155
To declare a variable, you can use:
155
156
156
157
var[] variable_name=string_value
@@ -195,6 +196,7 @@ But the `!NL!` macro is fine enough.
195
196
196
197
But note that if you're using variables, make sure to enable delayed expansion or else it won't work!
197
198
199
+
### Evaluate
198
200
To do math equations, do:
199
201
200
202
eq[] equation
@@ -217,7 +219,35 @@ Note that eq[] will always round up number, to do equation or to declare a varia
217
219
:: Import float
218
220
import[] float
219
221
float[] "variable_name" "equation"
220
-
222
+
223
+
### Console input
224
+
To declare a variable from user's input, try:
225
+
226
+
inp[] variable_name=
227
+
228
+
Note: If you do this, it will prints out "Enter name:" right next to the input
229
+
230
+
inp[] variable_name=Enter name:
231
+
232
+
To read data from a file:
233
+
234
+
inp[] variable_name=<file_name
235
+
236
+
Multi-line:
237
+
238
+
<file_name (
239
+
inp[] var1=
240
+
inp[] var2=
241
+
)
242
+
243
+
244
+
### Arrays, lists and tuples
245
+
#### FreakC standard's naming
246
+
* List: Multiple arguments delimitted by spaces, tails or semicolons.
247
+
* Array: Variables that follow an order, which should make a collection of data.
248
+
* Tuple: A list but should only be accessed through `scan_strs[]` or `for /f`.
249
+
250
+
#### Arrays
221
251
To declare a variable as an array, use:
222
252
223
253
var[] arr[array_index]=
@@ -241,30 +271,50 @@ Multi-dimensional:
241
271
242
272
Also, keep it in mind that this is the standard way of creating arrays in FreakC in order to receive a more "defined" structure to the code, as well as to make stuffs work well with the stdlib. You can also just do something like `var[] a\1=0` then it would still work, but will not work with the stdlib.
243
273
244
-
###FreakC standard's namings
245
-
* List: Multiple arguments delimitted by spaces, tails or semicolons.
246
-
* Array: Variables that follow an order, which should make a collections of data.
247
-
* Tuple: A list but should only be accessed through `scan_strs[]` or `for /f`.
274
+
#### List
275
+
Creating a list:
276
+
277
+
var[]list=1 2 3 4 5
248
278
249
-
To declare a variable from user's input, try:
279
+
Simplest way to iterate over **List**:
250
280
251
-
inp[] variable_name=
281
+
var[] list=1 2 3 4 5
282
+
scan_str[] %%i in (%list%) do (
283
+
:: Print out every elements
284
+
print[] %%i
285
+
)
252
286
253
-
Note: If you do this, it will prints out "Enter name:" right next to the input
287
+
It's basically just like a foreach loop.
254
288
255
-
inp[] variable_name=Enter name:
289
+
Indexing:
256
290
257
-
To read data from a file:
291
+
scan_strs[] "tokens=<position> delims=<delimiter>" %%i in (<list>) do (
292
+
:: Print out the element at position <position>
293
+
print[] %%i
294
+
)
258
295
259
-
inp[] variable_name=<file_name
296
+
Example:
260
297
261
-
Multi-line:
298
+
var[] list=1 2 3 4 5
299
+
scan_strs[] "tokens=3 delims= " %%i in (%list%) do (
300
+
:: Print out the element at position 3, which is 4
301
+
print[] %%i
302
+
)
262
303
263
-
<file_name (
264
-
inp[] var1=
265
-
inp[] var2=
304
+
Given that, you can have another way to iterate over a list: just create a loop from 0 to the length of the list, and use indexing like this.
305
+
306
+
List is extremely better in performance than array, and use much less memory since it doesn't create new variables, but it's not as convenient to just get a value from a specific index, and it's pretty hard to change values too. Make sure to use what serves you best.
307
+
308
+
#### Tuples
309
+
310
+
var[] tuple=`Simon`Sawicki`
311
+
for /F "tokens=1,2 delims=`" %%a in ("!tuple!") do (
312
+
echo Name : %%a
313
+
echo Surname: %%b
266
314
)
267
315
316
+
Technically a tuple is a list but use a different delimitter, and can not be iteratable and should be immutable as well.
317
+
268
318
### Maths
269
319
You can do Math equations with FreakC like this:
270
320
@@ -328,23 +378,6 @@ To print out every element of an array, you can write something like this:
328
378
loop[] %%n in (0,1,2) do (
329
379
print[] ^!a[%%n]^!
330
380
)
331
-
332
-
Actually, you can use foreach with splitted strings for **List**:
333
-
334
-
var[] list=1 2 3 4 5
335
-
scan_str[] %%i in (%list%) do (
336
-
::Print out every elements
337
-
print[] %%i
338
-
)
339
-
340
-
Tuples:
341
-
342
-
Actually, you can use foreach with splitted strings for **List**:
343
-
344
-
var[] list=1 2 3 4 5
345
-
scan_strs[] %%a in (%list%) do (
346
-
print[] %%a %%b %%c...
347
-
)
348
381
349
382
### Local and global variables
350
383
You can declare a global variable by just using all the ways mentioned recently.
0 commit comments