Skip to content

Commit a9e9158

Browse files
mrbentarikaugitbook-bot
authored andcommitted
GitBook: [#314] asterisk hell pt 33
1 parent 054082d commit a9e9158

File tree

9 files changed

+167
-206
lines changed

9 files changed

+167
-206
lines changed

beginner/control_flow_1/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ Sample output for bot user joining :
211211
```
212212

213213
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.\\
215215

216216
{% hint style="success" %}
217217
**Pro Tip :**\

beginner/datatypes_1/README.md

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@ description: >-
1212

1313
A string is a sequence of characters. It simply stores textual data. String literals can be created in two ways:
1414

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 :\
1616
\
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.\
1919
`\\` This creates a backslash character. (only using a single backslash character denotes an escape sequence hence this is necessary)\
2020
\
2121
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.\
2524
\
26-
**Example :** \
25+
**Example :**\
2726
`` `Yagpdb is a nice bot. ``\
2827
`` I like it very much` ``
2928

@@ -33,31 +32,30 @@ The _`string`_ datatype is the most common Data Type for storing string literals
3332

3433
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 :
3534

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).\
3736
`{{$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.\
4139
`{{$hex := 0xA1}}`\
4240
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.
4341

4442
{% 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}}`\
4745
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.
4846
{% endhint %}
4947

5048
{% 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).
5250

53-
Example : ` {{$num := toInt64 105}}`\
51+
Example : `{{$num := toInt64 105}}`\
5452
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_.\
5553
By default however (without explicit `toInt64` conversion) Integer literals are stored as _int_ data type.
5654
{% endhint %}
5755

5856
### Float
5957

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.\
6159
Example : `9.5` `12.3` `0.008`
6260

6361
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
6664

6765
{% hint style="info" %}
6866
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_.
7169
{% endhint %}
7270

7371
{% hint style="info" %}
7472
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.
7775
{% endhint %}
7876

7977
{% hint style="warning" %}
@@ -85,7 +83,7 @@ Unless otherwise specified, all numbers (integers/float) will be base-10 by defa
8583
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` .\
8684
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.\
8785
\
88-
**Example : ** `{{$x := true}} {{$y := not $x}}`\
86+
**Example:** `{{$x := true}} {{$y := not $x}}`\
8987
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.
9088

9189
## Variables
@@ -114,7 +112,7 @@ A variable is a storage location, with a specific type and an associated name. I
114112

115113
**Short Notes :**
116114

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)
118116

119117
{% hint style="info" %}
120118
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}}
171169

172170
#### Explanation :
173171

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

176174
#### **Mathematical Functions :**
177175

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.\
181179
\
182180
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.\
184182
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.
187185

188186
#### Output :
189187

@@ -192,9 +190,8 @@ Further Example : `{{$z := div 12 5}}` stores `2` in variable z.\
192190
{% hint style="success" %}
193191
**Pro Tip :** You can use the printf function to check the value( with %v) contained by a variable and it's datatype(with %T).\
194192
\
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 :\
197195
`Type : float64 Value : 1.5`\
198196
Notice how printf can accept arguments as well. More on printf can be found [here](https://golang.org/pkg/fmt/).
199197
{% endhint %}
200-

0 commit comments

Comments
 (0)