From 52e50e58c6674560056a4dcb787099d739284b02 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 6 Apr 2025 16:34:23 -0400 Subject: Change Set syntax from {x} to |x| --- docs/sets.md | 89 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 44 insertions(+), 45 deletions(-) (limited to 'docs') diff --git a/docs/sets.md b/docs/sets.md index 62351ed5..88e47e98 100644 --- a/docs/sets.md +++ b/docs/sets.md @@ -4,37 +4,36 @@ Sets represent an unordered collection of unique elements. These are implemented using hash tables. ```tomo -a := {10, 20, 30} -b := {20, 30} +a := |10, 20, 30| +b := |20, 30| >> a.overlap(b) -= {20} += |20| ``` ## Syntax -Sets are written using `{...}` curly braces with comma-separated items: +Sets are written using `|...|` vertical pipes with comma-separated items: ```tomo -nums := {10, 20, 30} +nums := |10, 20, 30| ``` -Empty sets must specify the set type explicitly and use `{/}` for an empty set -(because `{}` is an empty table). +Empty sets must specify the set type explicitly: ```tomo -empty : {Int} = {/} +empty : |Int| = || ``` -For type annotations, a set that holds items with type `T` is written as `{T}`. +For type annotations, a set that holds items with type `T` is written as `|T|`. ### Comprehensions Similar to arrays, sets can use comprehensions: ```tomo -set := {10*i for i in 10} -set2 := {10*i for i in 10 if i mod 2 == 0} -set3 := {-10, 10*i for i in 10} +set := |10*i for i in 10| +set2 := |10*i for i in 10 if i mod 2 == 0| +set3 := |-10, 10*i for i in 10| ``` ## Accessing Items @@ -44,7 +43,7 @@ Sets internally store their items in an array, which you can access with the view: ```tomo -set := {10, 20, 30} +set := |10, 20, 30| >> set.items = [10, 20, 30] ``` @@ -54,7 +53,7 @@ set := {10, 20, 30} Set length can be accessed by the `.length` field: ```tomo ->> {10, 20, 30}.length +>> |10, 20, 30|.length = 3 ``` @@ -76,23 +75,23 @@ iterating over any of the new values. ## Set Methods -- [`func add(set:{T}, item: T -> Void)`](#add) -- [`func add_all(set:@{T}, items: [T] -> Void)`](#add_all) -- [`func clear(set:@{T} -> Void)`](#clear) -- [`func has(set:{T}, item:T -> Bool)`](#has) -- [`func (set: {T}, other: {T}, strict: Bool = no -> Bool)`](#is_subset_of) -- [`func is_superset_of(set:{T}, other: {T}, strict: Bool = no -> Bool)`](#is_superset_of) -- [`func overlap(set:{T}, other: {T} -> {T})`](#overlap) -- [`func remove(set:@{T}, item: T -> Void)`](#remove) -- [`func remove_all(set:@{T}, items: [T] -> Void)`](#remove_all) -- [`func with(set:{T}, other: {T} -> {T})`](#with) -- [`func without(set:{T}, other: {T} -> {T})`](#without) +- [`func add(set:|T|, item: T -> Void)`](#add) +- [`func add_all(set:@|T|, items: [T] -> Void)`](#add_all) +- [`func clear(set:@|T| -> Void)`](#clear) +- [`func has(set:|T|, item:T -> Bool)`](#has) +- [`func (set: |T|, other: |T|, strict: Bool = no -> Bool)`](#is_subset_of) +- [`func is_superset_of(set:|T|, other: |T|, strict: Bool = no -> Bool)`](#is_superset_of) +- [`func overlap(set:|T|, other: |T| -> |T|)`](#overlap) +- [`func remove(set:@|T|, item: T -> Void)`](#remove) +- [`func remove_all(set:@|T|, items: [T] -> Void)`](#remove_all) +- [`func with(set:|T|, other: |T| -> |T|)`](#with) +- [`func without(set:|T|, other: |T| -> |T|)`](#without) ### `add` Adds an item to the set. ```tomo -func add(set:{T}, item: T -> Void) +func add(set:|T|, item: T -> Void) ``` - `set`: The mutable reference to the set. @@ -112,7 +111,7 @@ Nothing. Adds multiple items to the set. ```tomo -func add_all(set:@{T}, items: [T] -> Void) +func add_all(set:@|T|, items: [T] -> Void) ``` - `set`: The mutable reference to the set. @@ -132,7 +131,7 @@ Nothing. Removes all items from the set. ```tomo -func clear(set:@{T} -> Void) +func clear(set:@|T| -> Void) ``` - `set`: The mutable reference to the set. @@ -151,7 +150,7 @@ Nothing. Checks if the set contains a specified item. ```tomo -func has(set:{T}, item:T -> Bool) +func has(set:|T|, item:T -> Bool) ``` - `set`: The set to check. @@ -162,7 +161,7 @@ func has(set:{T}, item:T -> Bool) **Example:** ```tomo ->> {10, 20}.has(20) +>> |10, 20|.has(20) = yes ``` @@ -172,7 +171,7 @@ func has(set:{T}, item:T -> Bool) Checks if the set is a subset of another set. ```tomo -func (set: {T}, other: {T}, strict: Bool = no -> Bool) +func (set: |T|, other: |T|, strict: Bool = no -> Bool) ``` - `set`: The set to check. @@ -184,7 +183,7 @@ func (set: {T}, other: {T}, strict: Bool = no -> Bool) **Example:** ```tomo ->> {1, 2}.is_subset_of({1, 2, 3}) +>> |1, 2|.is_subset_of(|1, 2, 3|) = yes ``` @@ -194,7 +193,7 @@ func (set: {T}, other: {T}, strict: Bool = no -> Bool) Checks if the set is a superset of another set. ```tomo -func is_superset_of(set:{T}, other: {T}, strict: Bool = no -> Bool) +func is_superset_of(set:|T|, other: |T|, strict: Bool = no -> Bool) ``` - `set`: The set to check. @@ -206,14 +205,14 @@ func is_superset_of(set:{T}, other: {T}, strict: Bool = no -> Bool) **Example:** ```tomo ->> {1, 2, 3}.is_superset_of({1, 2}) +>> |1, 2, 3|.is_superset_of(|1, 2|) = yes ``` ### `overlap` Creates a new set with items that are in both the original set and another set. ```tomo -func overlap(set:{T}, other: {T} -> {T}) +func overlap(set:|T|, other: |T| -> |T|) ``` - `set`: The original set. @@ -224,8 +223,8 @@ A new set containing only items present in both sets. **Example:** ```tomo ->> {1, 2}.overlap({2, 3}) -= {2} +>> |1, 2|.overlap(|2, 3|) += |2| ``` --- @@ -234,7 +233,7 @@ A new set containing only items present in both sets. Removes an item from the set. ```tomo -func remove(set:@{T}, item: T -> Void) +func remove(set:@|T|, item: T -> Void) ``` - `set`: The mutable reference to the set. @@ -254,7 +253,7 @@ Nothing. Removes multiple items from the set. ```tomo -func remove_all(set:@{T}, items: [T] -> Void) +func remove_all(set:@|T|, items: [T] -> Void) ``` - `set`: The mutable reference to the set. @@ -274,7 +273,7 @@ Nothing. Creates a new set that is the union of the original set and another set. ```tomo -func with(set:{T}, other: {T} -> {T}) +func with(set:|T|, other: |T| -> |T|) ``` - `set`: The original set. @@ -285,8 +284,8 @@ A new set containing all items from both sets. **Example:** ```tomo ->> {1, 2}.with({2, 3}) -= {1, 2, 3} +>> |1, 2|.with(|2, 3|) += |1, 2, 3| ``` --- @@ -295,7 +294,7 @@ A new set containing all items from both sets. Creates a new set with items from the original set but without items from another set. ```tomo -func without(set:{T}, other: {T} -> {T}) +func without(set:|T|, other: |T| -> |T|) ``` - `set`: The original set. @@ -306,6 +305,6 @@ A new set containing items from the original set excluding those in the other se **Example:** ```tomo ->> {1, 2}.without({2, 3}) -= {1} +>> |1, 2|.without(|2, 3|) += |1| ``` -- cgit v1.2.3