forked from goplus/tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
486 additions
and
462 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
// Go+ supports _constants_ of character, string, boolean, | ||
// and numeric values. | ||
import ( | ||
"math" | ||
) | ||
// `const` declares a constant value. | ||
const s string = "constant" | ||
println s | ||
// A `const` statement can appear anywhere a `var` | ||
// statement can. | ||
const n = 500000000 | ||
// Constant expressions perform arithmetic with | ||
// arbitrary precision. | ||
const d = 3e20 / n | ||
println d | ||
// A numeric constant has no type until it's given | ||
// one, such as by an explicit conversion. | ||
println int64(d) | ||
// A number can be given a type by using it in a | ||
// context that requires one, such as a variable | ||
// assignment or function call. For example, here | ||
// `math.sin` expects a `float64`. | ||
println math.sin(n) | ||
// Go+ supports _constants_ of character, string, boolean, | ||
// and numeric values. | ||
|
||
import ( | ||
"math" | ||
) | ||
|
||
// `const` declares a constant value. | ||
const s string = "constant" | ||
|
||
println s | ||
|
||
// A `const` statement can appear anywhere a `var` | ||
// statement can. | ||
const n = 500000000 | ||
|
||
// Constant expressions perform arithmetic with | ||
// arbitrary precision. | ||
const d = 3e20 / n | ||
println d | ||
|
||
// A numeric constant has no type until it's given | ||
// one, such as by an explicit conversion. | ||
println int64(d) | ||
|
||
// A number can be given a type by using it in a | ||
// context that requires one, such as a variable | ||
// assignment or function call. For example, here | ||
// `math.sin` expects a `float64`. | ||
println math.sin(n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,28 @@ | ||
// In Go+, _variables_ are explicitly declared and used by | ||
// the compiler to e.g. check type-correctness of function | ||
// calls. | ||
|
||
// `var` declares 1 or more variables. | ||
var a = "initial" | ||
println a | ||
|
||
// You can declare multiple variables at once. | ||
var b, c int = 1, 2 | ||
println b, c | ||
|
||
// Go+ will infer the type of initialized variables. | ||
var d = true | ||
println d | ||
|
||
// Variables declared without a corresponding | ||
// initialization are _zero-valued_. For example, the | ||
// zero value for an `int` is `0`. | ||
var e int | ||
println e | ||
|
||
// The `:=` syntax is shorthand for declaring and | ||
// initializing a variable, e.g. for | ||
// `var f string = "apple"` in this case. | ||
f := "apple" | ||
println f | ||
// In Go+, _variables_ are explicitly declared and used by | ||
// the compiler to e.g. check type-correctness of function | ||
// calls. | ||
|
||
// `var` declares 1 or more variables. | ||
var a = "initial" | ||
|
||
println a | ||
|
||
// You can declare multiple variables at once. | ||
var b, c int = 1, 2 | ||
println b, c | ||
|
||
// Go+ will infer the type of initialized variables. | ||
var d = true | ||
println d | ||
|
||
// Variables declared without a corresponding | ||
// initialization are _zero-valued_. For example, the | ||
// zero value for an `int` is `0`. | ||
var e int | ||
println e | ||
|
||
// The `:=` syntax is shorthand for declaring and | ||
// initializing a variable, e.g. for | ||
// `var f string = "apple"` in this case. | ||
f := "apple" | ||
println f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,51 @@ | ||
// A string is a sequence of bytes that cannot be changed. Strings can contain any data | ||
// and are generally used to save text. | ||
// | ||
// We generally use double quotes "" to define a string, but note that there are specific | ||
// characters that have a specific meaning, which we call escaped characters, and these | ||
// escaped characters contain: | ||
// | ||
// <pre style="font-size:small"> | ||
// \n:line break | ||
// \r:Enter | ||
// \t:Tab | ||
// \u or \U:Unicode | ||
// \:Backslash | ||
// </pre> | ||
println("hello" + "\t" + "world") // hello world | ||
// If we want to know the length of the strings taken up by bytes, we can use Go+'s built-in | ||
// functions to calculate it: | ||
println(len("helloword")) // 9 | ||
// If we were to define a string, the grammar would be as follows: | ||
str := "helloword" | ||
println(str) // helloword | ||
println(len(str)) // 9 | ||
// We can stitch two strings together by +, appending the later string to the later of the | ||
// earlier string. | ||
str1 := "hello" + "word" | ||
println(str1) // helloword | ||
str2 := "my name is \t" | ||
str3 := "zs" | ||
println(str2 + str3) // my name is zs | ||
// If we want to define a multi-line string, Go+ supports that too. Using the traditional | ||
// "" is not possible across lines, we can use backquotes if we want to define a multi-line | ||
// string: ` | ||
const str4 = `First line | ||
Second line | ||
Third line | ||
` | ||
println(str4) | ||
// The code between the backquotes is not recognized by the editor, but only as part of | ||
// the string. | ||
// A string is a sequence of bytes that cannot be changed. Strings can contain any data | ||
// and are generally used to save text. | ||
// | ||
// We generally use double quotes "" to define a string, but note that there are specific | ||
// characters that have a specific meaning, which we call escaped characters, and these | ||
// escaped characters contain: | ||
// | ||
// <pre style="font-size:small"> | ||
// \n:line break | ||
// \r:Enter | ||
// \t:Tab | ||
// \u or \U:Unicode | ||
// \:Backslash | ||
// </pre> | ||
|
||
println("hello" + "\t" + "world") // hello world | ||
|
||
// If we want to know the length of the strings taken up by bytes, we can use Go+'s built-in | ||
// functions to calculate it: | ||
|
||
println(len("helloword")) // 9 | ||
|
||
// If we were to define a string, the grammar would be as follows: | ||
|
||
str := "helloword" | ||
println(str) // helloword | ||
println(len(str)) // 9 | ||
|
||
// We can stitch two strings together by +, appending the later string to the later of the | ||
// earlier string. | ||
|
||
str1 := "hello" + "word" | ||
println(str1) // helloword | ||
|
||
str2 := "my name is \t" | ||
str3 := "zs" | ||
|
||
println(str2 + str3) // my name is zs | ||
|
||
// If we want to define a multi-line string, Go+ supports that too. Using the traditional | ||
// "" is not possible across lines, we can use backquotes if we want to define a multi-line | ||
// string: ` | ||
|
||
const str4 = `First line | ||
Second line | ||
Third line | ||
` | ||
println(str4) | ||
|
||
// The code between the backquotes is not recognized by the editor, but only as part of | ||
// the string. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
// Branching with `if` and `else` in Go+ is | ||
// straight-forward. | ||
// Here's a basic example. | ||
if 7%2 == 0 { | ||
println "7 is even" | ||
} else { | ||
println "7 is odd" | ||
} | ||
// You can have an `if` statement without an else. | ||
if 8%4 == 0 { | ||
println "8 is divisible by 4" | ||
} | ||
// A statement can precede conditionals; any variables | ||
// declared in this statement are available in all | ||
// branches. | ||
if num := 9; num < 0 { | ||
println num, "is negative" | ||
} else if num < 10 { | ||
println num, "has 1 digit" | ||
} else { | ||
println num, "has multiple digits" | ||
} | ||
// Note that you don't need parentheses around conditions | ||
// in Go+, but that the braces are required. | ||
// Branching with `if` and `else` in Go+ is | ||
// straight-forward. | ||
|
||
// Here's a basic example. | ||
if 7%2 == 0 { | ||
println "7 is even" | ||
} else { | ||
println "7 is odd" | ||
} | ||
|
||
// You can have an `if` statement without an else. | ||
if 8%4 == 0 { | ||
println "8 is divisible by 4" | ||
} | ||
|
||
// A statement can precede conditionals; any variables | ||
// declared in this statement are available in all | ||
// branches. | ||
if num := 9; num < 0 { | ||
println num, "is negative" | ||
} else if num < 10 { | ||
println num, "has 1 digit" | ||
} else { | ||
println num, "has multiple digits" | ||
} | ||
|
||
// Note that you don't need parentheses around conditions | ||
// in Go+, but that the braces are required. |
Oops, something went wrong.