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: beginner/control_flow_1/README.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -211,7 +211,7 @@ Sample output for bot user joining :
211
211
```
212
212
213
213
Above snippet will print `This message has an attachment` if triggering message has an attachment. Notice how in this example we are using .Message.Attachments which is not of boolean data type as the if statement's condition. This is possible because non boolean variables are automatically converted to boolean when used in a condition according to the following logic :\
214
-
If the the data represents the **empty value**\[\*\*zero value\*\*( `nil` , `0`, `""` or `false` depending on data type) or empty slices/maps/channels ] of the associated data type, it is evaluated as `false` and otherwise as `true`. This makes determining if a certain value is nil or empty (or number is zero) very efficient.\\
214
+
If the the data represents the **empty value**\[**zero value**( `nil` , `0`, `""` or `false` depending on data type) or empty slices/maps/channels ] of the associated data type, it is evaluated as `false` and otherwise as `true`. This makes determining if a certain value is nil or empty (or number is zero) very efficient.\\
Copy file name to clipboardExpand all lines: beginner/datatypes_1/README.md
+29-32Lines changed: 29 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -12,18 +12,17 @@ description: >-
12
12
13
13
A string is a sequence of characters. It simply stores textual data. String literals can be created in two ways:
14
14
15
-
1.**Using Double Quotes : **String literals can be created by enclosing a sequence of characters within double quotation marks `"` . It can cannot contain newlines and allows usage of special escape sequences to represent certain characters. Some of them are :\
15
+
1.**Using Double Quotes:**String literals can be created by enclosing a sequence of characters within double quotation marks `"` . It can cannot contain newlines and allows usage of special escape sequences to represent certain characters. Some of them are :\
16
16
\
17
-
`\n`This produces a newline character (similar to pressing the enter key)\
18
-
`\"` This produces a double quotation mark `"` . This allows us to use double quotes inside quoted string literals.\
17
+
 This produces a newline character (similar to pressing the enter key)\
18
+
`\"` This produces a double quotation mark `"` . This allows us to use double quotes inside quoted string literals.\
19
19
`\\` This creates a backslash character. (only using a single backslash character denotes an escape sequence hence this is necessary)\
20
20
\
21
21
A more detailed list of other escape sequences can be found [here](http://xahlee.info/golang/golang\_string\_backslash\_escape.html).\
22
-
**Example :**`"Yagpdb is a nice bot.\nI like it very much."`\
23
-
24
-
2.**Using Backticks :** String literals can also be created in form of a _raw string literal _by enclosing it in backticks `` ` ``. It can contain all characters including newlines except for the backtick character. It does not support any escape sequences and is usually used to conveniently produce string literals which span multiple lines.\
22
+
**Example :**`"Yagpdb is a nice bot.\nI like it very much."`\\
23
+
2.**Using Backticks:** String literals can also be created in form of a \_raw string literal \_by enclosing it in backticks `` ` ``. It can contain all characters including newlines except for the backtick character. It does not support any escape sequences and is usually used to conveniently produce string literals which span multiple lines.\
25
24
\
26
-
**Example :**\
25
+
**Example :**\
27
26
`` `Yagpdb is a nice bot. ``\
28
27
`` I like it very much` ``
29
28
@@ -33,31 +32,30 @@ The _`string`_ datatype is the most common Data Type for storing string literals
33
32
34
33
Integers – like their mathematical counterpart – are numbers without a decimal component. In Yagpdb templating code, the maximum range of _int_ data type is from : -9223372036854775808 to 9223372036854775807. There are [different ways](https://golang.org/ref/spec#Integer\_literals) in which an integer literal can be created/specified but irrespective of how they are specified, they represent an unique number.The _`int`_ datatype is the most common Data Type for storing integer literals. Some common ways to specify integer literals are :
35
34
36
-
1.**As base 10 number : **As intimidating as it sounds, these are our normal plain numbers. So normal digits can be used to create number literals (remember that the first digit should be non zero for syntax reasons).\
35
+
1.**As base 10 number:**As intimidating as it sounds, these are our normal plain numbers. So normal digits can be used to create number literals (remember that the first digit should be non zero for syntax reasons).\
37
36
`{{$x := 105}}`\
38
-
Above statement assigns a [variable](https://yagpdb.gitbook.io/learnyagpdb/beginner/datatypes\_1#variables) named x with value 105 (base-10)\
39
-
40
-
2.**As a hexadecimal number : **You might have come across [hexadecimal numbers](https://simple.wikipedia.org/wiki/Hexadecimal) while reading about memory locations or hexadecimal codes for colors etc. While specifying a hexadecimal number, we have to precede the number with `0x` to denote that the following number represents a hexadecimal number. You can use digits from `0` to `9` and letters `a` to `e` to specify a hexadecimal number. Capitalization of the letters do not matter.\
37
+
Above statement assigns a [variable](https://yagpdb.gitbook.io/learnyagpdb/beginner/datatypes\_1#variables) named x with value 105 (base-10)\\
38
+
2.**As a hexadecimal number:** You might have come across [hexadecimal numbers](https://simple.wikipedia.org/wiki/Hexadecimal) while reading about memory locations or hexadecimal codes for colors etc. While specifying a hexadecimal number, we have to precede the number with `0x` to denote that the following number represents a hexadecimal number. You can use digits from `0` to `9` and letters `a` to `e` to specify a hexadecimal number. Capitalization of the letters do not matter.\
41
39
`{{$hex := 0xA1}}`\
42
40
Above statement assigns a [variable](https://yagpdb.gitbook.io/learnyagpdb/beginner/datatypes\_1#variables) named hex with value : 161(base-10) using an integer literal specified in hexadecimal format.
43
41
44
42
{% hint style="info" %}
45
-
Preceding an integer literal with 0 makes it interpreted as a number specified in [octal](https://simple.wikipedia.org/wiki/Octal) notation (base-8).\
46
-
Example : `{{$x := 011}}`\
43
+
Preceding an integer literal with 0 makes it interpreted as a number specified in [octal](https://simple.wikipedia.org/wiki/Octal) notation (base-8).\
44
+
Example : `{{$x := 011}}`\
47
45
stores 9 (base-10) in [variable](https://yagpdb.gitbook.io/learnyagpdb/beginner/datatypes\_1#variables) named x and not 11. In fact, `9` is written as `11` in octal notation.
48
46
{% endhint %}
49
47
50
48
{% hint style="info" %}
51
-
_int64_ is another data type which is very similar to _int_ but is always 64 bits size irrespective of compiler. int64 can be converted to int using the `toInt`function. Reverse can be achieved using `toInt64` function. Type conversion functions are listed [here](https://docs.yagpdb.xyz/reference/templates#type-conversion).
49
+
_int64_ is another data type which is very similar to _int_ but is always 64 bits size irrespective of compiler. int64 can be converted to int using the `toInt`function. Reverse can be achieved using `toInt64` function. Type conversion functions are listed [here](https://docs.yagpdb.xyz/reference/templates#type-conversion).
52
50
53
-
Example : `{{$num := toInt64 105}}`\
51
+
Example : `{{$num := toInt64 105}}`\
54
52
Stores 105 (base-10) in [variable](https://yagpdb.gitbook.io/learnyagpdb/beginner/datatypes\_1#variables) called num but as _int64_ data type and not _int_.\
55
53
By default however (without explicit `toInt64` conversion) Integer literals are stored as _int_ data type.
56
54
{% endhint %}
57
55
58
56
### Float
59
57
60
-
Floating point numbers are numbers that contain a decimal component (real numbers). They are specified with a number with a decimal point.\
58
+
Floating point numbers are numbers that contain a decimal component (real numbers). They are specified with a number with a decimal point.\
61
59
Example : `9.5``12.3``0.008`
62
60
63
61
Floating point literals also support some other formats such as scientific notation etc. elaborated [here](https://golang.org/ref/spec#Floating-point\_literals).
@@ -66,14 +64,14 @@ The _`float64`_ is the most common datatype you will encounter in Yagpdb for sto
66
64
67
65
{% hint style="info" %}
68
66
Note `10` represents an integer literal while `10.0` represents a floating point literal.\
69
-
Example : `{{num := 20.0}}`\
70
-
Stores 20.0 (base-10) in a [variable](https://yagpdb.gitbook.io/learnyagpdb/beginner/datatypes\_1#variables) called num with data type _float64_ and not _int_. 
67
+
Example : `{{num := 20.0}}`\
68
+
Stores 20.0 (base-10) in a [variable](https://yagpdb.gitbook.io/learnyagpdb/beginner/datatypes\_1#variables) called num with data type _float64_ and not _int_.
71
69
{% endhint %}
72
70
73
71
{% hint style="info" %}
74
72
function `toFloat` can be used to convert int to _float64_. reverse can be achieved via `toInt` function. However when a float is converted to integer, the decimal part is stripped in place of rounding it to nearest integer.\
75
-
Example : `{{$x := toInt 12.98}}`\
76
-
In the above statement, 12 (base-10) is stored in the [variable](https://yagpdb.gitbook.io/learnyagpdb/beginner/datatypes\_1#variables) named x and not 13. 
73
+
Example : `{{$x := toInt 12.98}}`\
74
+
In the above statement, 12 (base-10) is stored in the [variable](https://yagpdb.gitbook.io/learnyagpdb/beginner/datatypes\_1#variables) named x and not 13.
77
75
{% endhint %}
78
76
79
77
{% hint style="warning" %}
@@ -85,7 +83,7 @@ Unless otherwise specified, all numbers (integers/float) will be base-10 by defa
85
83
A boolean value (named after George Boole) is a special 1 bit integer type used to represent true and false (or on and off). There are two predefined boolean constants (both lowercase only) : `true` and `false` .\
86
84
Boolean values are very critical to control flow and are discussed in further detail there. A logical comparison function ( checking if two numbers are equal, checking if one number is greater than another etc.) and logical operation based functions ( and , or and not operations) will produce boolean values as output.\
87
85
\
88
-
**Example : **`{{$x := true}} {{$y := not $x}}`\
86
+
**Example:**`{{$x := true}} {{$y := not $x}}`\
89
87
Above snippet will store `true` in [variable](https://yagpdb.gitbook.io/learnyagpdb/beginner/datatypes\_1#variables) x and `false` in [variable](https://yagpdb.gitbook.io/learnyagpdb/beginner/datatypes\_1#variables) y.
90
88
91
89
## Variables
@@ -114,7 +112,7 @@ A variable is a storage location, with a specific type and an associated name. I
114
112
115
113
**Short Notes :**
116
114
117
-
In the above code snippet you can notice the `:=` operator. This operator is used to define a new variable and assigns it the value of the action's output or literal to its right. Every variable **must**be defined at least once before using it. Another operator `=` called assignment operator is used to assign a value a previously define variable. This will be covered in further detail later on. [Further reading in context of GO.](https://www.godesignpatterns.com/2014/04/assignment-vs-short-variable-declaration.html)
115
+
In the above code snippet you can notice the `:=` operator. This operator is used to define a new variable and assigns it the value of the action's output or literal to its right. Every variable **must**be defined at least once before using it. Another operator `=` called assignment operator is used to assign a value a previously define variable. This will be covered in further detail later on. [Further reading in context of GO.](https://www.godesignpatterns.com/2014/04/assignment-vs-short-variable-declaration.html)
118
116
119
117
{% hint style="info" %}
120
118
Note: All preceding and trailing white spaces (eg: space, newlines ) are always trimmed away in final output matching discord behavior.
@@ -171,19 +169,19 @@ Remember that : {{$quote_of_the_day}}
171
169
172
170
#### Explanation :
173
171
174
-
Above is an example of how variables can be extremely useful. Notice that by simply changing the value of the number stored in variable x, you can generate it's multiplication table. 
172
+
Above is an example of how variables can be extremely useful. Notice that by simply changing the value of the number stored in variable x, you can generate it's multiplication table.
175
173
176
174
#### **Mathematical Functions :**
177
175
178
-
`mult` here is a function type action which we have seen before. It multiplies the numbers provided to it (written after it) and gives the value of their product. The values that some function based actions similar to `mult` accept (or do their computation on) are called **arguments**. The data type of the value returned by the `mult` function is the data type of it's first argument.\
179
-
For example : `{{$x := mult 1 2.5}}`stores `2` in variable x.\
180
-
 `{{$y := mult 1.0 2.5}}` stores `2.5` in variable y.\
176
+
`mult` here is a function type action which we have seen before. It multiplies the numbers provided to it (written after it) and gives the value of their product. The values that some function based actions similar to `mult` accept (or do their computation on) are called **arguments**. The data type of the value returned by the `mult` function is the data type of it's first argument.\
177
+
For example : `{{$x := mult 1 2.5}}` stores `2` in variable x.\
178
+
`{{$y := mult 1.0 2.5}}` stores `2.5` in variable y.\
181
179
\
182
180
The `mult` function can also accept more than 2 arguments and works exactly the same way.\
183
-
For example : `{{$z := mult 2.2 2 4}}`stores `17.6` in variable z.\
181
+
For example : `{{$z := mult 2.2 2 4}}` stores `17.6` in variable z.\
184
182
There are other mathematical function for addition, subtraction, division, exponentiation etc. which work very similar to the `mult` function elaborated in the [docs](https://docs.yagpdb.xyz/reference/templates#math-functions).\
185
-
Further Example : `{{$z := div 12 5}}`stores `2` in variable z.\
186
-
 `{{$z := div (toFloat 12) 5}}` stores `2.4` in variable z.
183
+
Further Example : `{{$z := div 12 5}}` stores `2` in variable z.\
184
+
`{{$z := div (toFloat 12) 5}}` stores `2.4` in variable z.
187
185
188
186
#### Output :
189
187
@@ -192,9 +190,8 @@ Further Example : `{{$z := div 12 5}}` stores `2` in variable z.\
192
190
{% hint style="success" %}
193
191
**Pro Tip :** You can use the printf function to check the value( with %v) contained by a variable and it's datatype(with %T).\
194
192
\
195
-
**Example :**`{{$x := 1.5}} Type : {{printf "%T" $x}} Value : {{printf "%v" $x}}`\
196
-
The above code snippet will output :\
193
+
**Example :**`{{$x := 1.5}} Type : {{printf "%T" $x}} Value : {{printf "%v" $x}}`\
194
+
The above code snippet will output :\
197
195
`Type : float64 Value : 1.5`\
198
196
Notice how printf can accept arguments as well. More on printf can be found [here](https://golang.org/pkg/fmt/).
0 commit comments