diff options
| author | Cody <cody@codyq.dev> | 2022-12-15 14:18:13 -0600 |
|---|---|---|
| committer | Cody <cody@codyq.dev> | 2022-12-15 14:18:13 -0600 |
| commit | 900bd3d64ac4c5c4c1511ab8388da3f2ed77849f (patch) | |
| tree | 8de3006843d9dc717bf1c00d9942a068c90f413c /tour | |
| parent | bddb011df4999f7ffeeddf6a4b66e2da6ab19ea0 (diff) | |
| download | sloth-900bd3d64ac4c5c4c1511ab8388da3f2ed77849f.tar.gz | |
Replace `let` keyword with `val` and `var`
Thanks for pointing out that using `let` and `let mut` was stupid for a
scripting language @mworzala
Diffstat (limited to 'tour')
| -rw-r--r-- | tour/functions.sloth | 8 | ||||
| -rw-r--r-- | tour/literals.sloth | 42 | ||||
| -rw-r--r-- | tour/types.sloth | 12 | ||||
| -rw-r--r-- | tour/variables.sloth | 12 |
4 files changed, 37 insertions, 37 deletions
diff --git a/tour/functions.sloth b/tour/functions.sloth index e6c8b89..529d108 100644 --- a/tour/functions.sloth +++ b/tour/functions.sloth @@ -1,13 +1,13 @@ # Types can be inferred. # If inferrence fails it will be set to "any" unless strict mode is on pub fn add(lhs, rhs) { - let result = lhs + rhs; + val result = lhs + rhs; return result; } # ...or manually specified pub fn mul(lhs: i32, rhs: i32) -> i32 { - let result = lhs * rhs; + val result = lhs * rhs; return result; } @@ -16,14 +16,14 @@ pub fn mul(lhs: i32, rhs: i32) -> i32 { ## lhs: Left hand side of subtraction ## rhs: Right hand side of subtraction pub fn sub(lhs: i32, rhs: i32) -> i32 { - let result = lhs - rhs; + val result = lhs - rhs; return result; } ## Fizzbuzz implementation from 1 through 100 fn fizzbuzz() { for x in 1..=100 { - let message = match (x % 5, x % 3) { + val message = match (x % 5, x % 3) { (0, 0) => "FizzBuzz", (0, _) => "Fizz", (_, 0) => "Buzz", diff --git a/tour/literals.sloth b/tour/literals.sloth index 67e9071..4aa4533 100644 --- a/tour/literals.sloth +++ b/tour/literals.sloth @@ -1,32 +1,32 @@ # Literals -let number = 85; #TODO: Decide on default integer type -let number = 85.0; # f64 is the default float type +val number = 85; #TODO: Decide on default integer type +val number = 85.0; # f64 is the default float type -let number: u16 = 27; # If you want more control over memory usage you can specify a integer type -let number: u16 = 27u16; -let number: u16 = 0x1B; -let number: u16 = 0x1Bu16; +val number: u16 = 27; # If you want more control over memory usage you can specify a integer type +val number: u16 = 27u16; +val number: u16 = 0x1B; +val number: u16 = 0x1Bu16; -let number: BigInt = BigInt::from(73); #TODO: naming -let number: BigFloat = BigFloat::from(73); #TODO: naming +val number: BigInt = BigInt::from(73); #TODO: naming +val number: BigFloat = BigFloat::from(73); #TODO: naming -let chars: char = ' '; +val chars: char = ' '; -let strings: String = "Normal string"; -let strings: String = "Formated strings ${number}"; -let strings: String = """String literals"""; +val strings: String = "Normal string"; +val strings: String = "Formated strings ${number}"; +val strings: String = """String literals"""; -let regex: Regex = /[0-9A-F]/; +val regex: Regex = /[0-9A-F]/; -let list: List<i32> = [1, 2, 3, 2]; -let sets: Set<i32> = {1, 2, 3, 2}; +val list: List<i32> = [1, 2, 3, 2]; +val sets: Set<i32> = {1, 2, 3, 2}; -let maps = { +val maps = { "foo": 48, "bar": 97, }; -let maps: Map<String, i32> = { +val maps: Map<String, i32> = { "foo": 48, "bar": 97, }; @@ -41,7 +41,7 @@ maps.keys() # ["foo", "bar"] maps.values() # [48, 97] # Spreading -let lhs = [1, 2, 3]; -let rhs = [4, 5, 6]; -let combined_list = [..lhs, ..rhs, 2, 4, 6]; -let combined_sets = {..lhs, ..rhs, 2, 4, 6}; +val lhs = [1, 2, 3]; +val rhs = [4, 5, 6]; +val combined_list = [..lhs, ..rhs, 2, 4, 6]; +val combined_sets = {..lhs, ..rhs, 2, 4, 6}; diff --git a/tour/types.sloth b/tour/types.sloth index a47fd3a..c7ef2f5 100644 --- a/tour/types.sloth +++ b/tour/types.sloth @@ -6,7 +6,7 @@ type Person = { grades: Map<String, i32>, }; -let cody = Person { +val cody = Person { name: "Cody Q", age: 17, hobbies: { @@ -59,12 +59,12 @@ impl Color { (value * 255) as u8 } - let h = (hue * 6).floor() as i32; + val h = (hue * 6).floor() as i32; - let f = hue * 6 - h; - let p = value * (1 - saturation); - let q = value * (1 - f * saturation); - let t = value * (1 - (1 - f) * saturation); + val f = hue * 6 - h; + val p = value * (1 - saturation); + val q = value * (1 - f * saturation); + val t = value * (1 - (1 - f) * saturation); return match h { 0 => Color(c(value), c(t), c(p)), diff --git a/tour/variables.sloth b/tour/variables.sloth index d105716..c3a9137 100644 --- a/tour/variables.sloth +++ b/tour/variables.sloth @@ -1,12 +1,12 @@ -# Variables can be declared using the `let` keyword, however they will be deeply -# immutable. If you would like to make the variable mutable you can use `let mut` +# Variables can be declared using the `var` keyword, however they will be mutable. +# If you would like to make the variable immutable you can use `val` # # Variables can not be exported and can not be referrenced accross modules. -let x = 0; -let mut y = 0; +var x = 0; +val y = 0; -x = 5; # Invalid -y = 5; # Valid +x = 5; # Valid +y = 5; # Invalid # Constants can be declared using the `const` keyword, unlike variables they can # be exported and accessed across modules. |
