From 44b46d7e53313cc01ffae03d6401ea589266477b Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 11 Sep 2024 11:59:18 +0530 Subject: [PATCH 01/12] Add BBE for byte and expression equality --- examples/binary-data/binary_data.md | 3 +- examples/byte-type/bytes.bal | 11 +++++++ examples/byte-type/bytes.md | 7 ++++ examples/byte-type/bytes.metatags | 2 ++ examples/byte-type/bytes.out | 3 ++ .../expression_equality.bal | 33 +++++++++++++++++++ .../expression_equality.md | 11 +++++++ .../expression_equality.metatags | 2 ++ .../expression_equality.out | 8 +++++ examples/index.json | 14 ++++++++ examples/list-equality/list_equality.md | 3 +- 11 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 examples/byte-type/bytes.bal create mode 100644 examples/byte-type/bytes.md create mode 100644 examples/byte-type/bytes.metatags create mode 100644 examples/byte-type/bytes.out create mode 100644 examples/expression-equality/expression_equality.bal create mode 100644 examples/expression-equality/expression_equality.md create mode 100644 examples/expression-equality/expression_equality.metatags create mode 100644 examples/expression-equality/expression_equality.out diff --git a/examples/binary-data/binary_data.md b/examples/binary-data/binary_data.md index f493c0231c..cdcaaf9036 100644 --- a/examples/binary-data/binary_data.md +++ b/examples/binary-data/binary_data.md @@ -8,6 +8,5 @@ Binary data is represented by arrays of byte values. It is a special syntax for ## Related links - [Arrays](/learn/by-example/arrays) +- [Byte type](/learn/by-example/byte-type) - [Integers](/learn/by-example/integers) - -[comment]: # (Add byte type BBE link) diff --git a/examples/byte-type/bytes.bal b/examples/byte-type/bytes.bal new file mode 100644 index 0000000000..8903718014 --- /dev/null +++ b/examples/byte-type/bytes.bal @@ -0,0 +1,11 @@ +import ballerina/io; + +public function main() { + // Byte values ranging from 0 to 255 + byte b = 255; + io:println(b); + + // Byte values can be assigned to int + int i = b; + io:println(i); +} diff --git a/examples/byte-type/bytes.md b/examples/byte-type/bytes.md new file mode 100644 index 0000000000..6cf1e785e0 --- /dev/null +++ b/examples/byte-type/bytes.md @@ -0,0 +1,7 @@ +# Byte type + +The byte type in Ballerina represents an 8-bit unsigned integer, with values ranging from 0 to 255. + +::: code bytes.bal ::: + +::: out bytes.out ::: \ No newline at end of file diff --git a/examples/byte-type/bytes.metatags b/examples/byte-type/bytes.metatags new file mode 100644 index 0000000000..43e2b3f3e2 --- /dev/null +++ b/examples/byte-type/bytes.metatags @@ -0,0 +1,2 @@ +description: This BBE introduces Ballerina byte type. +keywords: ballerina, ballerina by example, bbe, bytes, byte, byte type diff --git a/examples/byte-type/bytes.out b/examples/byte-type/bytes.out new file mode 100644 index 0000000000..563293a448 --- /dev/null +++ b/examples/byte-type/bytes.out @@ -0,0 +1,3 @@ +$ bal run bytes.bal +255 +255 diff --git a/examples/expression-equality/expression_equality.bal b/examples/expression-equality/expression_equality.bal new file mode 100644 index 0000000000..30f62f2aae --- /dev/null +++ b/examples/expression-equality/expression_equality.bal @@ -0,0 +1,33 @@ +import ballerina/io; + +public function main() { + map student = {"name": "John", "age": "25"}; + map student2 = {"name": "John", "age": "25"}; + + // The output will be `true` because the values are the same. + io:println(student == student2); + + // The output will be `false` because the values are the same. + io:println(student != student2); + + // The output will be `false` because the references are different. + io:println(student === student2); + + // This assigns the reference of `student` to `student3`. + map student3 = student; + + // The output will be `true` because the references are the same. + io:println(student3 === student); + + // The output will be `false` because the references are the same. + io:println(student3 !== student); + + int a = 1; + anydata b = 1; + + // The output will be `true` because the values are the same. + io:println(a == b); + // Since simple type values do not have a storage identity, + // `===` will return `true` because the values are the same. + io:println(a === b); +} diff --git a/examples/expression-equality/expression_equality.md b/examples/expression-equality/expression_equality.md new file mode 100644 index 0000000000..b6cf8f5725 --- /dev/null +++ b/examples/expression-equality/expression_equality.md @@ -0,0 +1,11 @@ +# Expression equality + +In Ballerina, expression equality is determined using two operators: `==` for value equality and `===` for reference equality. The `==` operator checks for deep equality between two values by comparing the actual data they store. In contrast, the `===` operator checks whether two values share the same storage identity, meaning it compares whether the values reference the same memory location. +Values with storage identity, such as structured types like maps and arrays, are stored as references, so `===` can determine if two references point to the same underlying data. For simple types like, such as integers and booleans, which do not have storage identity, `===` behaves the same as `==`. + +::: code expression_equality.bal ::: + +::: out expression_equality.out ::: + +## Related links +- [Maps](/learn/by-example/maps) diff --git a/examples/expression-equality/expression_equality.metatags b/examples/expression-equality/expression_equality.metatags new file mode 100644 index 0000000000..40789bf305 --- /dev/null +++ b/examples/expression-equality/expression_equality.metatags @@ -0,0 +1,2 @@ +description: This BBE demonstrates expression equality checks in Ballerina. +keywords: ballerina, ballerina by example, bbe, ==, !=, ===, !==, equality diff --git a/examples/expression-equality/expression_equality.out b/examples/expression-equality/expression_equality.out new file mode 100644 index 0000000000..d982666d2f --- /dev/null +++ b/examples/expression-equality/expression_equality.out @@ -0,0 +1,8 @@ +$ bal run expression_equality.bal +true +false +false +true +false +true +true diff --git a/examples/index.json b/examples/index.json index 3acba6736b..9539640801 100644 --- a/examples/index.json +++ b/examples/index.json @@ -103,6 +103,13 @@ "verifyBuild": true, "verifyOutput": true, "isLearnByExample": true + }, + { + "name": "Byte type", + "url": "byte-type", + "verifyBuild": true, + "verifyOutput": true, + "isLearnByExample": true } ] }, @@ -475,6 +482,13 @@ "verifyBuild": true, "verifyOutput": true, "isLearnByExample": true + }, + { + "name": "Expression equality", + "url": "expression-equality", + "verifyBuild": true, + "verifyOutput": true, + "isLearnByExample": true } ] }, diff --git a/examples/list-equality/list_equality.md b/examples/list-equality/list_equality.md index d35398aecb..a0dec651c2 100644 --- a/examples/list-equality/list_equality.md +++ b/examples/list-equality/list_equality.md @@ -9,6 +9,5 @@ You can use `==` and `!=` on lists to check the deep equality of two lists: two ## Related links - [Tuples](/learn/by-example/tuples) - [Arrays](/learn/by-example/arrays) +- [Expression equality](/learn/by-example/expression-equality) - [List sub typing](/learn/by-example/list-subtyping) - -[comment]: # (Add equality expression link) From 38080503d6d29c882dd681aebd6990e48928834d Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 11 Sep 2024 13:40:50 +0530 Subject: [PATCH 02/12] Rename the byte_type files --- examples/byte-type/{bytes.bal => byte_type.bal} | 0 examples/byte-type/{bytes.md => byte_type.md} | 4 ++-- examples/byte-type/{bytes.metatags => byte_type.metatags} | 0 examples/byte-type/byte_type.out | 3 +++ examples/byte-type/bytes.out | 3 --- 5 files changed, 5 insertions(+), 5 deletions(-) rename examples/byte-type/{bytes.bal => byte_type.bal} (100%) rename examples/byte-type/{bytes.md => byte_type.md} (68%) rename examples/byte-type/{bytes.metatags => byte_type.metatags} (100%) create mode 100644 examples/byte-type/byte_type.out delete mode 100644 examples/byte-type/bytes.out diff --git a/examples/byte-type/bytes.bal b/examples/byte-type/byte_type.bal similarity index 100% rename from examples/byte-type/bytes.bal rename to examples/byte-type/byte_type.bal diff --git a/examples/byte-type/bytes.md b/examples/byte-type/byte_type.md similarity index 68% rename from examples/byte-type/bytes.md rename to examples/byte-type/byte_type.md index 6cf1e785e0..f732a45ebf 100644 --- a/examples/byte-type/bytes.md +++ b/examples/byte-type/byte_type.md @@ -2,6 +2,6 @@ The byte type in Ballerina represents an 8-bit unsigned integer, with values ranging from 0 to 255. -::: code bytes.bal ::: +::: code byte_type.bal ::: -::: out bytes.out ::: \ No newline at end of file +::: out byte_type.out ::: \ No newline at end of file diff --git a/examples/byte-type/bytes.metatags b/examples/byte-type/byte_type.metatags similarity index 100% rename from examples/byte-type/bytes.metatags rename to examples/byte-type/byte_type.metatags diff --git a/examples/byte-type/byte_type.out b/examples/byte-type/byte_type.out new file mode 100644 index 0000000000..8aea7bfd1a --- /dev/null +++ b/examples/byte-type/byte_type.out @@ -0,0 +1,3 @@ +$ bal run byte_type.bal +255 +255 diff --git a/examples/byte-type/bytes.out b/examples/byte-type/bytes.out deleted file mode 100644 index 563293a448..0000000000 --- a/examples/byte-type/bytes.out +++ /dev/null @@ -1,3 +0,0 @@ -$ bal run bytes.bal -255 -255 From faaf8de428c493cfd9dda544a0080d372349f55a Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 18 Sep 2024 11:58:15 +0530 Subject: [PATCH 03/12] Update comments in byte and expression equality --- examples/byte-type/byte_type.bal | 5 +++-- examples/byte-type/byte_type.metatags | 2 +- examples/expression-equality/expression_equality.bal | 8 ++++---- examples/expression-equality/expression_equality.md | 3 ++- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/byte-type/byte_type.bal b/examples/byte-type/byte_type.bal index 8903718014..1fa78778cc 100644 --- a/examples/byte-type/byte_type.bal +++ b/examples/byte-type/byte_type.bal @@ -1,11 +1,12 @@ import ballerina/io; public function main() { - // Byte values ranging from 0 to 255 + // The `byte` type consists of integers ranging from `0` to `255`. byte b = 255; io:println(b); - // Byte values can be assigned to int + // Since the set of possible `byte` values is a subset of `int` values, + // the `byte` type is a subtype of the `int` type. int i = b; io:println(i); } diff --git a/examples/byte-type/byte_type.metatags b/examples/byte-type/byte_type.metatags index 43e2b3f3e2..aa883b2787 100644 --- a/examples/byte-type/byte_type.metatags +++ b/examples/byte-type/byte_type.metatags @@ -1,2 +1,2 @@ -description: This BBE introduces Ballerina byte type. +description: This BBE introduces the Ballerina byte type. keywords: ballerina, ballerina by example, bbe, bytes, byte, byte type diff --git a/examples/expression-equality/expression_equality.bal b/examples/expression-equality/expression_equality.bal index 30f62f2aae..2da1dfa2fe 100644 --- a/examples/expression-equality/expression_equality.bal +++ b/examples/expression-equality/expression_equality.bal @@ -4,7 +4,7 @@ public function main() { map student = {"name": "John", "age": "25"}; map student2 = {"name": "John", "age": "25"}; - // The output will be `true` because the values are the same. + // The output will be `true` because the values are considered equal based on their content. io:println(student == student2); // The output will be `false` because the values are the same. @@ -13,7 +13,7 @@ public function main() { // The output will be `false` because the references are different. io:println(student === student2); - // This assigns the reference of `student` to `student3`. + // Assign the value assigned to the `student` variable to the `student3` variable. map student3 = student; // The output will be `true` because the references are the same. @@ -27,7 +27,7 @@ public function main() { // The output will be `true` because the values are the same. io:println(a == b); - // Since simple type values do not have a storage identity, - // `===` will return `true` because the values are the same. + // Since values of simple types do not have a storage identity, + // `===` will evaluate to `true` because the values are the same. io:println(a === b); } diff --git a/examples/expression-equality/expression_equality.md b/examples/expression-equality/expression_equality.md index b6cf8f5725..f7ecfb7570 100644 --- a/examples/expression-equality/expression_equality.md +++ b/examples/expression-equality/expression_equality.md @@ -1,7 +1,8 @@ # Expression equality In Ballerina, expression equality is determined using two operators: `==` for value equality and `===` for reference equality. The `==` operator checks for deep equality between two values by comparing the actual data they store. In contrast, the `===` operator checks whether two values share the same storage identity, meaning it compares whether the values reference the same memory location. -Values with storage identity, such as structured types like maps and arrays, are stored as references, so `===` can determine if two references point to the same underlying data. For simple types like, such as integers and booleans, which do not have storage identity, `===` behaves the same as `==`. + +Values with storage identity, such as structured types like maps and arrays, are stored as references, so `===` can determine if two references point to the same underlying data. For simple types such as integers and booleans, which do not have storage identity, `===` behaves the same as `==`. ::: code expression_equality.bal ::: From 13e522dde41cd3c1f09655e45ed4b7d9f99bb488 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 18 Sep 2024 12:46:44 +0530 Subject: [PATCH 04/12] Update comments on the expression equality bbe --- examples/expression-equality/expression_equality.bal | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/expression-equality/expression_equality.bal b/examples/expression-equality/expression_equality.bal index 2da1dfa2fe..5e68a17f32 100644 --- a/examples/expression-equality/expression_equality.bal +++ b/examples/expression-equality/expression_equality.bal @@ -7,7 +7,7 @@ public function main() { // The output will be `true` because the values are considered equal based on their content. io:println(student == student2); - // The output will be `false` because the values are the same. + // The output will be `false` because the values are not considered equal based on their content. io:println(student != student2); // The output will be `false` because the references are different. @@ -25,7 +25,7 @@ public function main() { int a = 1; anydata b = 1; - // The output will be `true` because the values are the same. + // The output will be `true` because the values are considered equal based on their content. io:println(a == b); // Since values of simple types do not have a storage identity, // `===` will evaluate to `true` because the values are the same. From d0021ae7331fa604f2d3a64b9b74393b615775d9 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 18 Sep 2024 15:26:57 +0530 Subject: [PATCH 05/12] update the expression equality bbe --- examples/expression-equality/expression_equality.bal | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/expression-equality/expression_equality.bal b/examples/expression-equality/expression_equality.bal index 5e68a17f32..d6dda4ac28 100644 --- a/examples/expression-equality/expression_equality.bal +++ b/examples/expression-equality/expression_equality.bal @@ -4,10 +4,11 @@ public function main() { map student = {"name": "John", "age": "25"}; map student2 = {"name": "John", "age": "25"}; - // The output will be `true` because the values are considered equal based on their content. + // The output will be `true` because the values are considered equal based on the + // equality of members. io:println(student == student2); - // The output will be `false` because the values are not considered equal based on their content. + // The output will be false because the values are not equal due to differences in their content. io:println(student != student2); // The output will be `false` because the references are different. @@ -25,7 +26,7 @@ public function main() { int a = 1; anydata b = 1; - // The output will be `true` because the values are considered equal based on their content. + // The output will be `true` because the values are equal. io:println(a == b); // Since values of simple types do not have a storage identity, // `===` will evaluate to `true` because the values are the same. From 1c5ae804ca78fd1a410c81eeaf3dd3a2a73e31e4 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 18 Sep 2024 15:30:49 +0530 Subject: [PATCH 06/12] Update the description of the expression equality bbe --- examples/expression-equality/expression_equality.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/expression-equality/expression_equality.md b/examples/expression-equality/expression_equality.md index f7ecfb7570..f0a4e203c8 100644 --- a/examples/expression-equality/expression_equality.md +++ b/examples/expression-equality/expression_equality.md @@ -1,6 +1,6 @@ # Expression equality -In Ballerina, expression equality is determined using two operators: `==` for value equality and `===` for reference equality. The `==` operator checks for deep equality between two values by comparing the actual data they store. In contrast, the `===` operator checks whether two values share the same storage identity, meaning it compares whether the values reference the same memory location. +In Ballerina, expression equality is determined using two operators: `==` for value equality and `===` for reference equality. The `==` operator checks for deep equality between two values by comparing the actual data. In contrast, the `===` operator checks whether two values share the same storage identity, meaning it checks if the values reference the same memory location. Values with storage identity, such as structured types like maps and arrays, are stored as references, so `===` can determine if two references point to the same underlying data. For simple types such as integers and booleans, which do not have storage identity, `===` behaves the same as `==`. From 80f2a32f610b9c7ce484652d91b6fc1226acf4e1 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 18 Sep 2024 16:39:20 +0530 Subject: [PATCH 07/12] Change the comments on the expression equality bbe --- examples/expression-equality/expression_equality.bal | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/expression-equality/expression_equality.bal b/examples/expression-equality/expression_equality.bal index d6dda4ac28..e2cb5c0630 100644 --- a/examples/expression-equality/expression_equality.bal +++ b/examples/expression-equality/expression_equality.bal @@ -8,7 +8,8 @@ public function main() { // equality of members. io:println(student == student2); - // The output will be false because the values are not equal due to differences in their content. + // The output will be `false` because the values are considered equal based on the + // equality of members. io:println(student != student2); // The output will be `false` because the references are different. From 070f77c5f68d0215361d6038b5b438a36642fdcd Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 19 Sep 2024 09:54:10 +0530 Subject: [PATCH 08/12] Add string and floating point examples --- .../expression-equality/expression_equality.bal | 16 ++++++++++++++++ .../expression-equality/expression_equality.out | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/examples/expression-equality/expression_equality.bal b/examples/expression-equality/expression_equality.bal index e2cb5c0630..9fb8561e57 100644 --- a/examples/expression-equality/expression_equality.bal +++ b/examples/expression-equality/expression_equality.bal @@ -32,4 +32,20 @@ public function main() { // Since values of simple types do not have a storage identity, // `===` will evaluate to `true` because the values are the same. io:println(a === b); + + decimal c = 1.0; + decimal d = 1.00; + // `===` and `==`` are the same for simple values except for floating point types. + // The output will be `true` because the values are equal. + io:println(c == d); + // The output will be `false` because `c` and `d` are distinct values with different precision. + io:println(c === d); + + string s1 = "Hello"; + string s2 = "Hello"; + + // The string type is a sequence type, not a simple type, + // but `==` and `===` still behave the same for string comparisons + io:println(s1 == s2); + io:println(s1 === s2); } diff --git a/examples/expression-equality/expression_equality.out b/examples/expression-equality/expression_equality.out index d982666d2f..52f6647e17 100644 --- a/examples/expression-equality/expression_equality.out +++ b/examples/expression-equality/expression_equality.out @@ -6,3 +6,7 @@ true false true true +true +false +true +true From 7c8380ad8213e9d1d2411b9552fdef75e67db040 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 19 Sep 2024 11:04:51 +0530 Subject: [PATCH 09/12] Add a separate section for expression equality bbe --- .../expression_equality.bal | 19 ++++++++--------- .../expression_equality.md | 4 ++-- examples/index.json | 21 ++++++++++++------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/examples/expression-equality/expression_equality.bal b/examples/expression-equality/expression_equality.bal index 9fb8561e57..59b8d6d82c 100644 --- a/examples/expression-equality/expression_equality.bal +++ b/examples/expression-equality/expression_equality.bal @@ -4,38 +4,38 @@ public function main() { map student = {"name": "John", "age": "25"}; map student2 = {"name": "John", "age": "25"}; - // The output will be `true` because the values are considered equal based on the + // The `==` check evaluates to `true` since the values are considered equal based on the // equality of members. io:println(student == student2); - // The output will be `false` because the values are considered equal based on the + // The `!=` check evaluates to `false` since the values are considered equal based on the // equality of members. io:println(student != student2); - // The output will be `false` because the references are different. + // The `===` check evaluates to `false` since references are different. io:println(student === student2); // Assign the value assigned to the `student` variable to the `student3` variable. map student3 = student; - // The output will be `true` because the references are the same. + // The `===` check evaluates to `true` since references are same. io:println(student3 === student); - // The output will be `false` because the references are the same. + // The `!==` check evaluates to `false` since references are same. io:println(student3 !== student); + // Since values of simple types do not have storage identity + // `===` and `==` return the same result, except for floating point values. int a = 1; anydata b = 1; // The output will be `true` because the values are equal. io:println(a == b); - // Since values of simple types do not have a storage identity, - // `===` will evaluate to `true` because the values are the same. io:println(a === b); decimal c = 1.0; decimal d = 1.00; - // `===` and `==`` are the same for simple values except for floating point types. + // The output will be `true` because the values are equal. io:println(c == d); // The output will be `false` because `c` and `d` are distinct values with different precision. @@ -44,8 +44,7 @@ public function main() { string s1 = "Hello"; string s2 = "Hello"; - // The string type is a sequence type, not a simple type, - // but `==` and `===` still behave the same for string comparisons + // The string type is a sequence type, but `===` and `==`` return the same result for string comparisons. io:println(s1 == s2); io:println(s1 === s2); } diff --git a/examples/expression-equality/expression_equality.md b/examples/expression-equality/expression_equality.md index f0a4e203c8..9b98e682e9 100644 --- a/examples/expression-equality/expression_equality.md +++ b/examples/expression-equality/expression_equality.md @@ -1,8 +1,8 @@ # Expression equality -In Ballerina, expression equality is determined using two operators: `==` for value equality and `===` for reference equality. The `==` operator checks for deep equality between two values by comparing the actual data. In contrast, the `===` operator checks whether two values share the same storage identity, meaning it checks if the values reference the same memory location. +Expression equality is determined using two operators: `==` for value equality and `===` for reference equality. The `==` operator checks for deep equality between two values by comparing the actual data. In contrast, the `===` operator checks whether two values share the same storage identity, meaning it checks if the values reference the same memory location. -Values with storage identity, such as structured types like maps and arrays, are stored as references, so `===` can determine if two references point to the same underlying data. For simple types such as integers and booleans, which do not have storage identity, `===` behaves the same as `==`. +Values with storage identity, such as structured types like maps and arrays, are stored as references, so `===` can determine if two references point to the same underlying data. For simple types such as integers and booleans, which do not have storage identity, `===` behaves the same as `==` except for floating point values. ::: code expression_equality.bal ::: diff --git a/examples/index.json b/examples/index.json index 9539640801..70d11f54ec 100644 --- a/examples/index.json +++ b/examples/index.json @@ -422,6 +422,20 @@ } ] }, + { + "title": "Equality", + "column": 0, + "category": "Language concepts", + "samples": [ + { + "name": "Expression equality", + "url": "expression-equality", + "verifyBuild": true, + "verifyOutput": true, + "isLearnByExample": true + } + ] + }, { "title": "Lists", "column": 1, @@ -482,13 +496,6 @@ "verifyBuild": true, "verifyOutput": true, "isLearnByExample": true - }, - { - "name": "Expression equality", - "url": "expression-equality", - "verifyBuild": true, - "verifyOutput": true, - "isLearnByExample": true } ] }, From 000ece2901ceaf8b35c88eca376de677a96d4ed8 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 19 Sep 2024 11:38:07 +0530 Subject: [PATCH 10/12] Update description in expression equality --- examples/expression-equality/expression_equality.bal | 9 +++++---- examples/expression-equality/expression_equality.md | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/expression-equality/expression_equality.bal b/examples/expression-equality/expression_equality.bal index 59b8d6d82c..b124e1bf87 100644 --- a/examples/expression-equality/expression_equality.bal +++ b/examples/expression-equality/expression_equality.bal @@ -29,22 +29,23 @@ public function main() { int a = 1; anydata b = 1; - // The output will be `true` because the values are equal. + // The `==` and `===` checks evaluates to `true` since the values are equal. io:println(a == b); io:println(a === b); decimal c = 1.0; decimal d = 1.00; - // The output will be `true` because the values are equal. + // The `==` check evaluates to `true` since the values are equal. io:println(c == d); - // The output will be `false` because `c` and `d` are distinct values with different precision. + // The `===` check evaluates to `false` since `c` and `d` are distinct values with different precision. io:println(c === d); string s1 = "Hello"; string s2 = "Hello"; - // The string type is a sequence type, but `===` and `==`` return the same result for string comparisons. + // String values also do not have storage identity, and `===` checks are + // the same as `==` checks for string values also. io:println(s1 == s2); io:println(s1 === s2); } diff --git a/examples/expression-equality/expression_equality.md b/examples/expression-equality/expression_equality.md index 9b98e682e9..5741bd1b7b 100644 --- a/examples/expression-equality/expression_equality.md +++ b/examples/expression-equality/expression_equality.md @@ -2,7 +2,7 @@ Expression equality is determined using two operators: `==` for value equality and `===` for reference equality. The `==` operator checks for deep equality between two values by comparing the actual data. In contrast, the `===` operator checks whether two values share the same storage identity, meaning it checks if the values reference the same memory location. -Values with storage identity, such as structured types like maps and arrays, are stored as references, so `===` can determine if two references point to the same underlying data. For simple types such as integers and booleans, which do not have storage identity, `===` behaves the same as `==` except for floating point values. +Values with storage identity, such as structured types like maps and arrays, have an identity that comes from the location where the value is stored. For such values, the `===` check determines if two references point to the same location. For simple types such as integers and booleans, which do not have storage identity, `===` behaves the same as `==` except for floating point values. ::: code expression_equality.bal ::: From 1ec419168f983865bcf7f9f3ec6955c2ac7c2418 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 19 Sep 2024 15:26:48 +0530 Subject: [PATCH 11/12] Add unsigned8 for metadata tags --- examples/byte-type/byte_type.metatags | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/byte-type/byte_type.metatags b/examples/byte-type/byte_type.metatags index aa883b2787..3ebfdc2f35 100644 --- a/examples/byte-type/byte_type.metatags +++ b/examples/byte-type/byte_type.metatags @@ -1,2 +1,2 @@ description: This BBE introduces the Ballerina byte type. -keywords: ballerina, ballerina by example, bbe, bytes, byte, byte type +keywords: ballerina, ballerina by example, bbe, bytes, byte, byte type, unsigned8 From ab8cb505580c2d2d2f4be7de4d771109f5a1eeb8 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 19 Sep 2024 15:29:38 +0530 Subject: [PATCH 12/12] Add reference link for integer subtypes --- examples/byte-type/byte_type.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/byte-type/byte_type.md b/examples/byte-type/byte_type.md index f732a45ebf..d361e4935f 100644 --- a/examples/byte-type/byte_type.md +++ b/examples/byte-type/byte_type.md @@ -4,4 +4,7 @@ The byte type in Ballerina represents an 8-bit unsigned integer, with values ran ::: code byte_type.bal ::: -::: out byte_type.out ::: \ No newline at end of file +::: out byte_type.out ::: + +## Related links +- [Built-in integer subtypes](/learn/by-example/built-in-integer-subtypes/) \ No newline at end of file