Skip to content

Commit fc208b9

Browse files
Update TUTORIAL.md
1 parent 2e71323 commit fc208b9

File tree

1 file changed

+65
-32
lines changed

1 file changed

+65
-32
lines changed

TUTORIAL.md

Lines changed: 65 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ It won't print out "print[]", but it will print out "echo", because FreakC will
151151
# Variables
152152

153153
## Variables
154+
### String
154155
To declare a variable, you can use:
155156

156157
var[] variable_name=string_value
@@ -195,6 +196,7 @@ But the `!NL!` macro is fine enough.
195196

196197
But note that if you're using variables, make sure to enable delayed expansion or else it won't work!
197198

199+
### Evaluate
198200
To do math equations, do:
199201

200202
eq[] equation
@@ -217,7 +219,35 @@ Note that eq[] will always round up number, to do equation or to declare a varia
217219
:: Import float
218220
import[] float
219221
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
221251
To declare a variable as an array, use:
222252

223253
var[] arr[array_index]=
@@ -241,30 +271,50 @@ Multi-dimensional:
241271

242272
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.
243273

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
248278

249-
To declare a variable from user's input, try:
279+
Simplest way to iterate over **List**:
250280

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+
)
252286

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.
254288

255-
inp[] variable_name=Enter name:
289+
Indexing:
256290

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+
)
258295

259-
inp[] variable_name=<file_name
296+
Example:
260297

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+
)
262303

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
266314
)
267315

316+
Technically a tuple is a list but use a different delimitter, and can not be iteratable and should be immutable as well.
317+
268318
### Maths
269319
You can do Math equations with FreakC like this:
270320

@@ -328,23 +378,6 @@ To print out every element of an array, you can write something like this:
328378
loop[] %%n in (0,1,2) do (
329379
print[] ^!a[%%n]^!
330380
)
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-
)
348381

349382
### Local and global variables
350383
You can declare a global variable by just using all the ways mentioned recently.

0 commit comments

Comments
 (0)