diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/arrays.md | 98 | ||||
| -rw-r--r-- | docs/enums.md | 2 | ||||
| -rw-r--r-- | docs/functions.md | 2 | ||||
| -rw-r--r-- | docs/integers.md | 44 | ||||
| -rw-r--r-- | docs/iterators.md | 8 | ||||
| -rw-r--r-- | docs/langs.md | 10 | ||||
| -rw-r--r-- | docs/nums.md | 114 | ||||
| -rw-r--r-- | docs/operators.md | 28 | ||||
| -rw-r--r-- | docs/optionals.md | 2 | ||||
| -rw-r--r-- | docs/paths.md | 142 | ||||
| -rw-r--r-- | docs/pointers.md | 8 | ||||
| -rw-r--r-- | docs/reductions.md | 4 | ||||
| -rw-r--r-- | docs/serialization.md | 8 | ||||
| -rw-r--r-- | docs/sets.md | 24 | ||||
| -rw-r--r-- | docs/structs.md | 4 | ||||
| -rw-r--r-- | docs/tables.md | 24 | ||||
| -rw-r--r-- | docs/text.md | 116 |
17 files changed, 319 insertions, 319 deletions
diff --git a/docs/arrays.md b/docs/arrays.md index 8ea51f01..ec114442 100644 --- a/docs/arrays.md +++ b/docs/arrays.md @@ -29,16 +29,16 @@ Arrays can also use comprehensions, where you specify how to dynamically create all the elements by iteration instead of manually specifying each: ```tomo ->> [i*10 for i in 3:to(8)] +>> [i*10 for i in (3).to(8)] = [30, 40, 50, 60, 70, 80] ->> [i*10 for i in 3:to(8) if i != 4] +>> [i*10 for i in (3).to(8) if i != 4] = [30, 50, 60, 70, 80] ``` Comprehensions can be combined with regular items or other comprehensions: ```tomo ->> [-1, i*10 for i in 3:to(8), i for i in 3] +>> [-1, i*10 for i in (3).to(8), i for i in 3] = [-1, 30, 40, 50, 60, 70, 80, 1, 2, 3] ``` @@ -122,7 +122,7 @@ in bytes between each element in the array. The reason this is mentioned is that it is possible to create immutable slices of arrays in constant time by creating a new struct that points to the appropriate starting place for the array items and has the appropriate stride. The upshot is that a method like -`array:reversed()` does not actually copy the array, it simply returns a struct +`array.reversed()` does not actually copy the array, it simply returns a struct that points to the back of the array with a negative stride. Arrays adhere to copy-on-write semantics, so we can cheaply create many read-only references to the same data, and only need to do copying if we plan to modify data. After @@ -146,13 +146,13 @@ explicitly perform an assignment operation on the variable or call a method on the variable. Because it would be tedious to require users to write all array operations as -pure functions like `array = array:with_value_at_index(value=x, index=i)`, Tomo +pure functions like `array = array.with_value_at_index(value=x, index=i)`, Tomo provides the familiar imperative syntax for modifying arrays, but keeps the semantics of the pure functional style. Writing `array[i] = x` is -_semantically_ equivalent to `array = array:with_value_at_index(value=x, +_semantically_ equivalent to `array = array.with_value_at_index(value=x, index=i)`, but much more readable and easy to write. Similarly, -`array:insert(x)` is semantically equivalent to `array = -array:with_value_inserted(x)`. We implement these mutating methods as functions +`array.insert(x)` is semantically equivalent to `array = +array.with_value_inserted(x)`. We implement these mutating methods as functions that take a pointer to an array variable, which then either mutate the array's data in-place (if this is the only thing referencing that data) or construct a new array and store its value in the memory where the array variable is stored. @@ -210,7 +210,7 @@ behavior that you get in Python when you create a `list`: nums := @[10, 20, 30] tmp := nums -nums:insert(40) +nums.insert(40) >> tmp = @[10, 20, 30, 40] ``` @@ -278,13 +278,13 @@ place where it would be found if it were inserted and the array were sorted. **Example:** ```tomo ->> [1, 3, 5, 7, 9]:binary_search(5) +>> [1, 3, 5, 7, 9].binary_search(5) = 3 ->> [1, 3, 5, 7, 9]:binary_search(-999) +>> [1, 3, 5, 7, 9].binary_search(-999) = 1 ->> [1, 3, 5, 7, 9]:binary_search(999) +>> [1, 3, 5, 7, 9].binary_search(999) = 6 ``` @@ -305,7 +305,7 @@ A new array with every `step`-th element from the original array. **Example:** ```tomo ->> [1, 2, 3, 4, 5, 6]:by(2) +>> [1, 2, 3, 4, 5, 6].by(2) = [1, 3, 5] ``` @@ -325,7 +325,7 @@ Nothing. **Example:** ```tomo ->> my_array:clear() +>> my_array.clear() ``` --- @@ -344,7 +344,7 @@ A table mapping each element to its count. **Example:** ```tomo ->> [10, 20, 30, 30, 30]:counts() +>> [10, 20, 30, 30, 30].counts() = {10=1, 20=1, 30=3} ``` @@ -365,10 +365,10 @@ The index of the first occurrence or `!Int` if not found. **Example:** ```tomo ->> [10, 20, 30, 40, 50]:find(20) +>> [10, 20, 30, 40, 50].find(20) = 2 : Int? ->> [10, 20, 30, 40, 50]:find(9999) +>> [10, 20, 30, 40, 50].find(9999) = none : Int? ``` @@ -391,9 +391,9 @@ item matches. **Example:** ```tomo ->> [4, 5, 6]:find(func(i:&Int): i:is_prime()) +>> [4, 5, 6].find(func(i:&Int): i.is_prime()) = 5 : Int? ->> [4, 6, 8]:find(func(i:&Int): i:is_prime()) +>> [4, 6, 8].find(func(i:&Int): i.is_prime()) = none : Int? ``` @@ -414,7 +414,7 @@ A new array starting from the specified index. **Example:** ```tomo ->> [10, 20, 30, 40, 50]:from(3) +>> [10, 20, 30, 40, 50].from(3) = [30, 40, 50] ``` @@ -434,7 +434,7 @@ func has(arr: [T] -> Bool) **Example:** ```tomo ->> [10, 20, 30]:has(20) +>> [10, 20, 30].has(20) = yes ``` @@ -458,8 +458,8 @@ The removed top element of the heap or `none` if the array is empty. **Example:** ```tomo >> my_heap := [30, 10, 20] ->> my_heap:heapify() ->> my_heap:heap_pop() +>> my_heap.heapify() +>> my_heap.heap_pop() = 10 ``` @@ -483,7 +483,7 @@ Nothing. **Example:** ```tomo ->> my_heap:heap_push(10) +>> my_heap.heap_push(10) ``` --- @@ -505,7 +505,7 @@ Nothing. **Example:** ```tomo >> my_heap := [30, 10, 20] ->> my_heap:heapify() +>> my_heap.heapify() ``` --- @@ -529,11 +529,11 @@ Nothing. **Example:** ```tomo >> arr := [10, 20] ->> arr:insert(30) +>> arr.insert(30) >> arr = [10, 20, 30] ->> arr:insert(999, at=2) +>> arr.insert(999, at=2) >> arr = [10, 999, 20, 30] ``` @@ -559,11 +559,11 @@ Nothing. **Example:** ```tomo arr := [10, 20] -arr:insert_all([30, 40]) +arr.insert_all([30, 40]) >> arr = [10, 20, 30, 40] -arr:insert_all([99, 100], at=2) +arr.insert_all([99, 100], at=2) >> arr = [10, 99, 100, 20, 30, 40] ``` @@ -590,12 +590,12 @@ otherwise the item at the given index. ```tomo >> arr := [10, 20, 30, 40] ->> arr:pop() +>> arr.pop() = 40 >> arr = &[10, 20, 30] ->> arr:pop(index=2) +>> arr.pop(index=2) = 20 >> arr = &[10, 30] @@ -620,7 +620,7 @@ A random element from the array. **Example:** ```tomo ->> [10, 20, 30]:random() +>> [10, 20, 30].random() = 20 ``` @@ -643,11 +643,11 @@ Nothing. **Example:** ```tomo arr := [10, 20, 30, 40, 50] -arr:remove_at(2) +arr.remove_at(2) >> arr = [10, 30, 40, 50] -arr:remove_at(2, count=2) +arr.remove_at(2, count=2) >> arr = [10, 50] ``` @@ -671,11 +671,11 @@ Nothing. **Example:** ```tomo arr := [10, 20, 10, 20, 30] -arr:remove_item(10) +arr.remove_item(10) >> arr = [20, 20, 30] -arr:remove_item(20, max_count=1) +arr.remove_item(20, max_count=1) >> arr = [20, 30] ``` @@ -696,7 +696,7 @@ A slice of the array with elements in reverse order. **Example:** ```tomo ->> [10, 20, 30]:reversed() +>> [10, 20, 30].reversed() = [30, 20, 10] ``` @@ -734,7 +734,7 @@ A list of sampled elements from the array. **Example:** ```tomo ->> [10, 20, 30]:sample(2, weights=[90%, 5%, 5%]) +>> [10, 20, 30].sample(2, weights=[90%, 5%, 5%]) = [10, 10] ``` @@ -757,7 +757,7 @@ Nothing. **Example:** ```tomo ->> arr:shuffle() +>> arr.shuffle() ``` --- @@ -779,7 +779,7 @@ A new array with shuffled elements. **Example:** ```tomo ->> [10, 20, 30, 40]:shuffled() +>> [10, 20, 30, 40].shuffled() = [40, 10, 30, 20] ``` @@ -803,10 +803,10 @@ second-to-last, and so on. **Example:** ```tomo ->> [10, 20, 30, 40, 50]:slice(2, 4) +>> [10, 20, 30, 40, 50].slice(2, 4) = [20, 30, 40] ->> [10, 20, 30, 40, 50]:slice(-3, -2) +>> [10, 20, 30, 40, 50].slice(-3, -2) = [30, 40] ``` @@ -829,11 +829,11 @@ Nothing. **Example:** ```tomo arr := [40, 10, -30, 20] -arr:sort() +arr.sort() >> arr = [-30, 10, 20, 40] -arr:sort(func(a,b:&Int): a:abs() <> b:abs()) +arr.sort(func(a,b:&Int): a.abs() <> b.abs()) >> arr = [10, 20, -30, 40] ``` @@ -856,10 +856,10 @@ A new array with sorted elements. **Example:** ```tomo ->> [40, 10, -30, 20]:sorted() +>> [40, 10, -30, 20].sorted() = [-30, 10, 20, 40] ->> [40, 10, -30, 20]:sorted(func(a,b:&Int): a:abs() <> b:abs()) +>> [40, 10, -30, 20].sorted(func(a,b:&Int): a.abs() <> b.abs()) = [10, 20, -30, 40] ``` @@ -880,10 +880,10 @@ A new array containing elements from the start up to the specified index. **Example:** ```tomo ->> [10, 20, 30, 40, 50]:to(3) +>> [10, 20, 30, 40, 50].to(3) = [10, 20, 30] ->> [10, 20, 30, 40, 50]:to(-2) +>> [10, 20, 30, 40, 50].to(-2) = [10, 20, 30, 40] ``` @@ -903,6 +903,6 @@ A set containing only unique elements from the array. **Example:** ```tomo ->> [10, 20, 10, 10, 30]:unique() +>> [10, 20, 10, 10, 30].unique() = {10, 20, 30} ``` diff --git a/docs/enums.md b/docs/enums.md index 72e4f3be..45321d25 100644 --- a/docs/enums.md +++ b/docs/enums.md @@ -85,4 +85,4 @@ enum VariousThings(AnInteger(i:Int), TwoWords(word1, word2:Text), Nothing): ``` Functions defined in an enum's namespace can be invoked as methods with `:` if -the first argument is the enum's type or a pointer to one (`vt:doop()`). +the first argument is the enum's type or a pointer to one (`vt.doop()`). diff --git a/docs/functions.md b/docs/functions.md index 9f95277f..ba5e86b3 100644 --- a/docs/functions.md +++ b/docs/functions.md @@ -35,7 +35,7 @@ callsite: ``` **Note:** Default arguments are re-evaluated at the callsite for each function -call, so if your default argument is `func foo(x=random:int(1,10) -> Int)`, then +call, so if your default argument is `func foo(x=random.int(1,10) -> Int)`, then each time you call the function without an `x` argument, it will give you a new random number. diff --git a/docs/integers.md b/docs/integers.md index 5681388c..bdef827d 100644 --- a/docs/integers.md +++ b/docs/integers.md @@ -120,7 +120,7 @@ rounding _towards zero_, and modulus never gives negative results: Each integer type has its own version of the following functions. Functions can be called either on the type itself: `Int.sqrt(x)` or as a method call: -`x:sqrt()`. Method call syntax is preferred. +`x.sqrt()`. Method call syntax is preferred. - [`func abs(x: Int -> Int)`](#abs) - [`func choose(n: Int, k: Int -> Int)`](#choose) @@ -151,7 +151,7 @@ The absolute value of `x`. **Example:** ```tomo ->> -10:abs() +>> (-10).abs() = 10 ``` @@ -159,8 +159,8 @@ The absolute value of `x`. ### `choose` Computes the binomial coefficient of the given numbers (the equivalent of `n` -choose `k` in combinatorics). This is equal to `n:factorial()/(k:factorial() * -(n-k):factorial())`. +choose `k` in combinatorics). This is equal to `n.factorial()/(k.factorial() * +(n-k).factorial())`. ```tomo func choose(n: Int, k: Int -> Int) @@ -175,7 +175,7 @@ The binomial coefficient, equivalent to the number of ways to uniquely choose **Example:** ```tomo ->> 4:choose(2) +>> (4).choose(2) = 6 ``` @@ -198,7 +198,7 @@ The first argument clamped between the other two arguments. **Example:** ```tomo ->> 2:clamped(5, 10) +>> (2).clamped(5, 10) = 5 ``` @@ -218,7 +218,7 @@ The factorial of the given integer. **Example:** ```tomo ->> 10:factorial() +>> (10).factorial() = 3628800 ``` @@ -239,7 +239,7 @@ A string representation of the integer, padded to the specified number of digits **Example:** ```tomo ->> 42:format(digits=5) +>> (42).format(digits=5) = "00042" ``` @@ -262,7 +262,7 @@ The hexadecimal string representation of the integer. **Example:** ```tomo ->> 255:hex(digits=4, uppercase=yes, prefix=yes) +>> (255).hex(digits=4, uppercase=yes, prefix=yes) = "0x00FF" ``` @@ -289,9 +289,9 @@ func is_prime(x: Int, reps: Int = 50 -> Bool) **Example:** ```tomo ->> 7:is_prime() +>> (7).is_prime() = yes ->> 6:is_prime() +>> (6).is_prime() = no ``` @@ -317,7 +317,7 @@ The next prime number greater than `x`. **Example:** ```tomo ->> 11:next_prime() +>> (11).next_prime() = 13 ``` @@ -339,7 +339,7 @@ The octal string representation of the integer. **Example:** ```tomo ->> 64:octal(digits=4, prefix=yes) +>> (64).octal(digits=4, prefix=yes) = "0o0100" ``` @@ -362,8 +362,8 @@ An iterator function that counts onward from the starting integer. **Example:** ```tomo nums : &[Int] = &[] -for i in 5:onward(): - nums:insert(i) +for i in (5).onward(): + nums.insert(i) stop if i == 10 >> nums[] = [5, 6, 7, 8, 9, 10] @@ -425,7 +425,7 @@ The previous prime number less than `x`. **Example:** ```tomo ->> 11:prev_prime() +>> (11).prev_prime() = 7 ``` @@ -445,9 +445,9 @@ The integer part of the square root of `x`. **Example:** ```tomo ->> 16:sqrt() +>> (16).sqrt() = 4 ->> 17:sqrt() +>> (17).sqrt() = 4 ``` @@ -470,13 +470,13 @@ An iterator function that returns each integer in the given range (inclusive). **Example:** ```tomo ->> 2:to(5) +>> (2).to(5) = func(->Int?) ->> [x for x in 2:to(5)] +>> [x for x in (2).to(5)] = [2, 3, 4, 5] ->> [x for x in 5:to(2)] +>> [x for x in (5).to(2)] = [5, 4, 3, 2] ->> [x for x in 2:to(5, step=2)] +>> [x for x in (2).to(5, step=2)] = [2, 4] ``` diff --git a/docs/iterators.md b/docs/iterators.md index ff7ed138..8d585ccb 100644 --- a/docs/iterators.md +++ b/docs/iterators.md @@ -8,13 +8,13 @@ For example, the `Path.each_line()` API method returns a function that successively gets one line from a file at a time until the file is exhausted: ```tomo -(./test.txt):write(" +(./test.txt).write(" line one line two line three ") ->> iter := (./test.txt):each_line() +>> iter := (./test.txt).each_line() >> iter() = "line one" : Text? >> iter() @@ -24,7 +24,7 @@ successively gets one line from a file at a time until the file is exhausted: >> iter() = none : Text? -for line in (./test.txt):each_line(): +for line in (./test.txt).each_line(): pass ``` @@ -38,7 +38,7 @@ func primes_up_to(limit:Int): if n > limit: return !Int - while not n:is_prime(): + while not n.is_prime(): n += 1 n += 1 diff --git a/docs/langs.md b/docs/langs.md index d7225ae5..aec9cfa9 100644 --- a/docs/langs.md +++ b/docs/langs.md @@ -11,7 +11,7 @@ where a different type of string is needed. ```tomo lang HTML: convert(t:Text -> HTML): - t = t:translate({ + t = t.translate({ "&" = "&", "<" = "<", ">" = ">", @@ -75,14 +75,14 @@ instead of building a global function called `execute()` that takes a ```tomo lang Sh: convert(text:Text -> Sh): - return Sh.from_text("'" ++ text:replace("'", "''") ++ "'") + return Sh.from_text("'" ++ text.replace("'", "''") ++ "'") func execute(sh:Sh -> Text): ... dir := ask("List which dir? ") cmd := $Sh@(ls -l @dir) -result := cmd:execute() +result := cmd.execute() ``` ## Conversions @@ -94,12 +94,12 @@ another type's block or at the top level. ```tomo lang Sh: convert(text:Text -> Sh): - return Sh.from_text("'" ++ text:replace("'", "''") ++ "'") + return Sh.from_text("'" ++ text.replace("'", "''") ++ "'") struct Foo(x,y:Int): convert(f:Foo -> Sh): return Sh.from_text("$(f.x),$(f.y)") convert(texts:[Text] -> Sh): - return $Sh" ":join([Sh(t) for t in texts]) + return $Sh" ".join([Sh(t) for t in texts]) ``` diff --git a/docs/nums.md b/docs/nums.md index 02859d28..36dedcac 100644 --- a/docs/nums.md +++ b/docs/nums.md @@ -115,7 +115,7 @@ provided are not NaN. Each Num type has its own version of the following functions. Functions can be called either on the type itself: `Num.sqrt(x)` or as a method call: -`x:sqrt()`. Method call syntax is preferred. +`x.sqrt()`. Method call syntax is preferred. --- @@ -184,7 +184,7 @@ The absolute value of `n`. **Example:** ```tomo ->> -3.5:abs() +>> (-3.5).abs() = 3.5 ``` @@ -204,7 +204,7 @@ The arc cosine of `x` in radians. **Example:** ```tomo ->> 0.0:acos() // -> (π/2) +>> (0.0).acos() // -> (π/2) = 1.5708 ``` @@ -224,7 +224,7 @@ The inverse hyperbolic cosine of `x`. **Example:** ```tomo ->> 1.0:acosh() +>> (1.0).acosh() = 0 ``` @@ -244,7 +244,7 @@ The arc sine of `x` in radians. **Example:** ```tomo ->> 0.5:asin() // -> (π/6) +>> (0.5).asin() // -> (π/6) = 0.5236 ``` @@ -264,7 +264,7 @@ The inverse hyperbolic sine of `x`. **Example:** ```tomo ->> 0.0:asinh() +>> (0.0).asinh() = 0 ``` @@ -284,7 +284,7 @@ The arc tangent of `x` in radians. **Example:** ```tomo ->> 1.0:atan() // -> (π/4) +>> (1.0).atan() // -> (π/4) = 0.7854 ``` @@ -325,7 +325,7 @@ The inverse hyperbolic tangent of `x`. **Example:** ```tomo ->> 0.5:atanh() +>> (0.5).atanh() = 0.5493 ``` @@ -345,7 +345,7 @@ The cube root of `x`. **Example:** ```tomo ->> 27.0:cbrt() +>> (27.0).cbrt() = 3 ``` @@ -365,7 +365,7 @@ The smallest integer greater than or equal to `x`. **Example:** ```tomo ->> 3.2:ceil() +>> (3.2).ceil() = 4 ``` @@ -388,7 +388,7 @@ The first argument clamped between the other two arguments. **Example:** ```tomo ->> 2.5:clamped(5.5, 10.5) +>> (2.5).clamped(5.5, 10.5) = 5.5 ``` @@ -409,7 +409,7 @@ A number with the magnitude of `x` and the sign of `y`. **Example:** ```tomo ->> 3.0:copysign(-1) +>> (3.0).copysign(-1) = -3 ``` @@ -429,7 +429,7 @@ The cosine of `x`. **Example:** ```tomo ->> 0.0:cos() +>> (0.0).cos() = 1 ``` @@ -449,7 +449,7 @@ The hyperbolic cosine of `x`. **Example:** ```tomo ->> 0.0:cosh() +>> (0.0).cosh() = 1 ``` @@ -469,7 +469,7 @@ The error function of `x`. **Example:** ```tomo ->> 0.0:erf() +>> (0.0).erf() = 0 ``` @@ -489,7 +489,7 @@ The complementary error function of `x`. **Example:** ```tomo ->> 0.0:erfc() +>> (0.0).erfc() = 1 ``` @@ -509,7 +509,7 @@ The value of \( e^x \). **Example:** ```tomo ->> 1.0:exp() +>> (1.0).exp() = 2.7183 ``` @@ -529,7 +529,7 @@ The value of \( 2^x \). **Example:** ```tomo ->> 3.0:exp2() +>> (3.0).exp2() = 8 ``` @@ -549,7 +549,7 @@ The value of \( e^x - 1 \). **Example:** ```tomo ->> 1.0:expm1() +>> (1.0).expm1() = 1.7183 ``` @@ -572,7 +572,7 @@ The positive difference \( \max(0, x - y) \). ```tomo fd ->> 5.0:fdim(3) +>> (5.0).fdim(3) = 2 ``` @@ -592,7 +592,7 @@ The largest integer less than or equal to `x`. **Example:** ```tomo ->> 3.7:floor() +>> (3.7).floor() = 3 ``` @@ -613,7 +613,7 @@ A text representation of the number with the specified precision. **Example:** ```tomo ->> 3.14159:format(precision=2) +>> (3.14159).format(precision=2) = "3.14" ``` @@ -654,9 +654,9 @@ func isfinite(n: Num -> Bool) **Example:** ```tomo ->> 1.0:isfinite() +>> (1.0).isfinite() = yes ->> Num.INF:isfinite() +>> Num.INF.isfinite() = no ``` @@ -676,9 +676,9 @@ func isinf(n: Num -> Bool) **Example:** ```tomo ->> Num.INF:isinf() +>> Num.INF.isinf() = yes ->> 1.0:isinf() +>> (1.0).isinf() = no ``` @@ -698,7 +698,7 @@ The Bessel function of the first kind of order 0 of `x`. **Example:** ```tomo ->> 0.0:j0() +>> (0.0).j0() = 1 ``` @@ -718,7 +718,7 @@ The Bessel function of the first kind of order 1 of `x`. **Example:** ```tomo ->> 0.0:j1() +>> (0.0).j1() = 0 ``` @@ -738,7 +738,7 @@ The natural logarithm of `x`. **Example:** ```tomo ->> Num.E:log() +>> Num.E.log() = 1 ``` @@ -758,7 +758,7 @@ The base-10 logarithm of `x`. **Example:** ```tomo ->> 100.0:log10() +>> (100.0).log10() = 2 ``` @@ -778,7 +778,7 @@ The value of \( \log(1 + x) \). **Example:** ```tomo ->> 1.0:log1p() +>> (1.0).log1p() = 0.6931 ``` @@ -798,7 +798,7 @@ The base-2 logarithm of `x`. **Example:** ```tomo ->> 8.0:log2() +>> (8.0).log2() = 3 ``` @@ -818,7 +818,7 @@ The binary exponent of `x`. **Example:** ```tomo ->> 8.0:logb() +>> (8.0).logb() = 3 ``` @@ -840,9 +840,9 @@ The interpolated number between `x` and `y` based on `amount`. **Example:** ```tomo ->> 0.5:mix(10, 20) +>> (0.5).mix(10, 20) = 15 ->> 0.25:mix(10, 20) +>> (0.25).mix(10, 20) = 12.5 ``` @@ -867,13 +867,13 @@ func near(x: Num, y: Num, ratio: Num = 1e-9, min_epsilon: Num = 1e-9 -> Bool) **Example:** ```tomo ->> 1.0:near(1.000000001) +>> (1.0).near(1.000000001) = yes ->> 100.0:near(110, ratio=0.1) +>> (100.0).near(110, ratio=0.1) = yes ->> 5.0:near(5.1, min_epsilon=0.1) +>> (5.0).near(5.1, min_epsilon=0.1) = yes ``` @@ -894,7 +894,7 @@ The next representable value after `x` in the direction of `y`. **Example:** ```tomo ->> 1.0:nextafter(1.1) +>> (1.0).nextafter(1.1) = 1.0000000000000002 ``` @@ -938,9 +938,9 @@ A text representation of the number as a percentage with a percent sign. **Example:** ```tomo ->> 0.5:percent() +>> (0.5).percent() = "50%" ->> (1./3.):percent(2) +>> (1./3.).percent(2) = "33.33%" ``` @@ -960,9 +960,9 @@ The nearest integer value of `x`. **Example:** ```tomo ->> 3.5:rint() +>> (3.5).rint() = 4 ->> 2.5:rint() +>> (2.5).rint() = 2 ``` @@ -982,9 +982,9 @@ The nearest integer value of `x`. **Example:** ```tomo ->> 2.3:round() +>> (2.3).round() = 2 ->> 2.7:round() +>> (2.7).round() = 3 ``` @@ -1005,7 +1005,7 @@ A text representation of the number in scientific notation with the specified pr **Example:** ```tomo ->> 12345.6789:scientific(precision=2) +>> (12345.6789).scientific(precision=2) = "1.23e+04" ``` @@ -1025,7 +1025,7 @@ The significand of `x`. **Example:** ```tomo ->> 1234.567:significand() +>> (1234.567).significand() = 0.1234567 ``` @@ -1045,7 +1045,7 @@ The sine of `x`. **Example:** ```tomo ->> 0.0:sin() +>> (0.0).sin() = 0 ``` @@ -1065,7 +1065,7 @@ The hyperbolic sine of `x`. **Example:** ```tomo ->> 0.0:sinh() +>> (0.0).sinh() = 0 ``` @@ -1085,7 +1085,7 @@ The square root of `x`. **Example:** ```tomo ->> 16.0:sqrt() +>> (16.0).sqrt() = 4 ``` @@ -1105,7 +1105,7 @@ The tangent of `x`. **Example:** ```tomo ->> 0.0:tan() +>> (0.0).tan() = 0 ``` @@ -1125,7 +1125,7 @@ The hyperbolic tangent of `x`. **Example:** ```tomo ->> 0.0:tanh() +>> (0.0).tanh() = 0 ``` @@ -1145,7 +1145,7 @@ The gamma function of `x`. **Example:** ```tomo ->> 1.0:tgamma() +>> (1.0).tgamma() = 1 ``` @@ -1165,9 +1165,9 @@ The integer part of `x` towards zero. **Example:** ```tomo ->> 3.7:trunc() +>> (3.7).trunc() = 3 ->> (-3.7):trunc() +>> (-3.7).trunc() = -3 ``` @@ -1187,7 +1187,7 @@ The Bessel function of the second kind of order 0 of `x`. **Example:** ```tomo ->> 1.0:y0() +>> (1.0).y0() = -0.7652 ``` @@ -1207,6 +1207,6 @@ The Bessel function of the second kind of order 1 of `x`. **Example:** ```tomo ->> 1.0:y1() +>> (1.0).y1() = 0.4401 ``` diff --git a/docs/operators.md b/docs/operators.md index a304cf35..548891e7 100644 --- a/docs/operators.md +++ b/docs/operators.md @@ -37,7 +37,7 @@ It's particularly handy for using the array `sort()` method, which takes a function that returns a signed integer: ```tomo ->> foos:sort(func(a,b:&Foo): a.length <> b.length) +>> foos.sort(func(a,b:&Foo): a.length <> b.length) ``` ## Reducers @@ -110,12 +110,12 @@ struct Foo(x,y:Int): >> (+: f.x for f in foos) = -9 ->> (or):is_even() foos +>> (or).is_even() foos = yes // Shorthand for: ->> (or) f:is_even() for f in foos +>> (or) f.is_even() for f in foos ->> (+.x:abs(): foos) +>> (+.x.abs(): foos) = 11 ``` @@ -144,7 +144,7 @@ Here's some examples: ```tomo // Get the largest absolute value number: ->> 3 _max_:abs() -15 +>> 3 _max_.abs() -15 = -15 struct Person(name:Text, age:Int) @@ -164,7 +164,7 @@ struct Person(name:Text, age:Int) The keyed comparison can chain together multiple field accesses, array index operations, method calls, etc. If you wanted to, for example, get the item -whose `x` field has the highest absolute value, you could use `_max_.x:abs()`. +whose `x` field has the highest absolute value, you could use `_max_.x.abs()`. ### Working with Reducers @@ -177,7 +177,7 @@ object using them: >> (_max_: nums) = 30 ->> (_max_:abs(): nums) +>> (_max_.abs(): nums) = -40 ``` @@ -221,7 +221,7 @@ func plus(T, T)->T ``` In an addition expression `a + b` between two objects of the same type, the -method `a:plus(b)` will be invoked, which returns a new value of the same type. +method `a.plus(b)` will be invoked, which returns a new value of the same type. #### Subtraction @@ -230,7 +230,7 @@ func minus(T, T)->T ``` In a subtraction expression `a - b` between two objects of the same type, the -method `a:minus(b)` will be invoked, which returns a new value of the same type. +method `a.minus(b)` will be invoked, which returns a new value of the same type. #### Multiplication @@ -239,9 +239,9 @@ func times(T, T)->T func scaled_by(T, N)->T ``` -The multiplication expression `a * b` invokes either the `a:times(b)` method, -if `a` and `b` are the same non-numeric type, or `a:scaled_by(b)` if `a` is -non-numeric and `b` is numeric, or `b:scaled_by(a)` if `b` is non-numeric and +The multiplication expression `a * b` invokes either the `a.times(b)` method, +if `a` and `b` are the same non-numeric type, or `a.scaled_by(b)` if `a` is +non-numeric and `b` is numeric, or `b.scaled_by(a)` if `b` is non-numeric and `a` is numeric. In all cases, a new value of the non-numeric type is returned. #### Division @@ -250,7 +250,7 @@ non-numeric and `b` is numeric, or `b:scaled_by(a)` if `b` is non-numeric and func divided_by(T, N)->T ``` -In a division expression `a / b` the method `a:divided_by(b)` will be invoked +In a division expression `a / b` the method `a.divided_by(b)` will be invoked if `a` has type `T` and `b` has a numeric type `N`. #### Exponentiation @@ -260,7 +260,7 @@ func power(T, N)->T ``` In an exponentiation expression, `a ^ b`, if `a` has type `T` and `b` has a -numeric type `N`, then the method `a:power(b)` will be invoked. +numeric type `N`, then the method `a.power(b)` will be invoked. #### Modulus diff --git a/docs/optionals.md b/docs/optionals.md index ff4252d1..7b100dc7 100644 --- a/docs/optionals.md +++ b/docs/optionals.md @@ -119,7 +119,7 @@ func do_stuff(matches:[Text]): pass for line in lines: - matches := line:matches($/{..},{..}/) or skip + matches := line.matches($/{..},{..}/) or skip # The `or skip` above means that if we're here, `matches` is non-none: do_stuff(matches) ``` diff --git a/docs/paths.md b/docs/paths.md index ac60d864..af179ede 100644 --- a/docs/paths.md +++ b/docs/paths.md @@ -92,9 +92,9 @@ accessed, or `none` if no such file or directory exists. **Example:** ```tomo ->> (./file.txt):accessed() +>> (./file.txt).accessed() = 1704221100? ->> (./not-a-file):accessed() +>> (./not-a-file).accessed() = none ``` @@ -117,7 +117,7 @@ Nothing. **Example:** ```tomo -(./log.txt):append("extra line$(\n)") +(./log.txt).append("extra line$(\n)") ``` --- @@ -139,7 +139,7 @@ Nothing. **Example:** ```tomo -(./log.txt):append_bytes([104[B], 105[B]]) +(./log.txt).append_bytes([104[B], 105[B]]) ``` --- @@ -158,7 +158,7 @@ The base name of the file or directory. **Example:** ```tomo ->> (./path/to/file.txt):base_name() +>> (./path/to/file.txt).base_name() = "file.txt" ``` @@ -181,15 +181,15 @@ value if the file couldn't be read. **Example:** ```tomo # Safely handle file not being readable: -if lines := (./file.txt):by_line(): +if lines := (./file.txt).by_line(): for line in lines: - say(line:upper()) + say(line.upper()) else: say("Couldn't read file!") # Assume the file is readable and error if that's not the case: -for line in (/dev/stdin):by_line()!: - say(line:upper()) +for line in (/dev/stdin).by_line()!: + say(line.upper()) ``` --- @@ -208,11 +208,11 @@ func can_execute(path: Path -> Bool) **Example:** ```tomo ->> (/bin/sh):can_execute() +>> (/bin/sh).can_execute() = yes ->> (/usr/include/stdlib.h):can_execute() +>> (/usr/include/stdlib.h).can_execute() = no ->> (/non/existant/file):can_execute() +>> (/non/existant/file).can_execute() = no ``` @@ -232,11 +232,11 @@ func can_read(path: Path -> Bool) **Example:** ```tomo ->> (/usr/include/stdlib.h):can_read() +>> (/usr/include/stdlib.h).can_read() = yes ->> (/etc/shadow):can_read() +>> (/etc/shadow).can_read() = no ->> (/non/existant/file):can_read() +>> (/non/existant/file).can_read() = no ``` @@ -256,11 +256,11 @@ func can_write(path: Path -> Bool) **Example:** ```tomo ->> (/tmp):can_write() +>> (/tmp).can_write() = yes ->> (/etc/passwd):can_write() +>> (/etc/passwd).can_write() = no ->> (/non/existant/file):can_write() +>> (/non/existant/file).can_write() = no ``` @@ -286,9 +286,9 @@ changed, or `none` if no such file or directory exists. **Example:** ```tomo ->> (./file.txt):changed() +>> (./file.txt).changed() = 1704221100? ->> (./not-a-file):changed() +>> (./not-a-file).changed() = none ``` @@ -309,7 +309,7 @@ A new path representing the child. **Example:** ```tomo ->> (./directory):child("file.txt") +>> (./directory).child("file.txt") = (./directory/file.txt) ``` @@ -330,7 +330,7 @@ A list of paths for the children. **Example:** ```tomo ->> (./directory):children(include_hidden=yes) +>> (./directory).children(include_hidden=yes) = [".git", "foo.txt"] ``` @@ -352,7 +352,7 @@ Nothing. **Example:** ```tomo -(./new_directory):create_directory() +(./new_directory).create_directory() ``` --- @@ -371,7 +371,7 @@ func exists(path: Path -> Bool) **Example:** ```tomo ->> (/):exists() +>> (/).exists() = yes ``` @@ -393,9 +393,9 @@ replace the `~` with an absolute path to the user's home directory. **Example:** ```tomo ->> (~/foo):expand_home() # Assume current user is 'user' +>> (~/foo).expand_home() # Assume current user is 'user' = /home/user/foo ->> (/foo):expand_home() # No change +>> (/foo).expand_home() # No change = /foo ``` @@ -418,13 +418,13 @@ no file extension. **Example:** ```tomo ->> (./file.tar.gz):extension() +>> (./file.tar.gz).extension() = "tar.gz" ->> (./file.tar.gz):extension(full=no) +>> (./file.tar.gz).extension(full=no) = "gz" ->> (/foo):extension() +>> (/foo).extension() = "" ->> (./.git):extension() +>> (./.git).extension() = "" ``` @@ -445,7 +445,7 @@ A list of file paths. **Example:** ```tomo ->> (./directory):files(include_hidden=yes) +>> (./directory).files(include_hidden=yes) = [(./directory/file1.txt), (./directory/file2.txt)] ``` @@ -498,20 +498,20 @@ A list of file paths that match the glob. **Example:** ```tomo # Current directory includes: foo.txt, baz.txt, qux.jpg, .hidden ->> (./*):glob() +>> (./*).glob() = [(./foo.txt), (./baz.txt), (./qux.jpg)] ->> (./*.txt):glob() +>> (./*.txt).glob() = [(./foo.txt), (./baz.txt)] ->> (./*.{txt,jpg}):glob() +>> (./*.{txt,jpg}).glob() = [(./foo.txt), (./baz.txt), (./qux.jpg)] ->> (./.*):glob() +>> (./.*).glob() = [(./.hidden)] # Globs with no matches return an empty array: ->> (./*.xxx):glob() +>> (./*.xxx).glob() = [] ``` @@ -532,9 +532,9 @@ The name of the group which owns the file or directory, or `none` if the path do **Example:** ```tomo ->> (/bin):group() +>> (/bin).group() = "root" ->> (/non/existent/file):group() +>> (/non/existent/file).group() = none ``` @@ -555,10 +555,10 @@ func is_directory(path: Path, follow_symlinks=yes -> Bool) **Example:** ```tomo ->> (./directory/):is_directory() +>> (./directory/).is_directory() = yes ->> (./file.txt):is_directory() +>> (./file.txt).is_directory() = no ``` @@ -579,10 +579,10 @@ func is_file(path: Path, follow_symlinks=yes -> Bool) **Example:** ```tomo ->> (./file.txt):is_file() +>> (./file.txt).is_file() = yes ->> (./directory/):is_file() +>> (./directory/).is_file() = no ``` @@ -603,7 +603,7 @@ func is_socket(path: Path, follow_symlinks=yes -> Bool) **Example:** ```tomo ->> (./socket):is_socket() +>> (./socket).is_socket() = yes ``` @@ -623,7 +623,7 @@ func is_symlink(path: Path -> Bool) **Example:** ```tomo ->> (./link):is_symlink() +>> (./link).is_symlink() = yes ``` @@ -645,9 +645,9 @@ modified, or `none` if no such file or directory exists. **Example:** ```tomo ->> (./file.txt):modified() +>> (./file.txt).modified() = 1704221100? ->> (./not-a-file):modified() +>> (./not-a-file).modified() = none ``` @@ -668,9 +668,9 @@ The name of the user who owns the file or directory, or `none` if the path does **Example:** ```tomo ->> (/bin):owner() +>> (/bin).owner() = "root" ->> (/non/existent/file):owner() +>> (/non/existent/file).owner() = none ``` @@ -690,7 +690,7 @@ The path of the parent directory. **Example:** ```tomo ->> (./path/to/file.txt):parent() +>> (./path/to/file.txt).parent() = (./path/to/) ``` @@ -713,10 +713,10 @@ raised. **Example:** ```tomo ->> (./hello.txt):read() +>> (./hello.txt).read() = "Hello"? ->> (./nosuchfile.xxx):read() +>> (./nosuchfile.xxx).read() = none ``` --- @@ -738,10 +738,10 @@ returned. **Example:** ```tomo ->> (./hello.txt):read() +>> (./hello.txt).read() = [72[B], 101[B], 108[B], 108[B], 111[B]]? ->> (./nosuchfile.xxx):read() +>> (./nosuchfile.xxx).read() = none ``` @@ -762,7 +762,7 @@ The relative path. **Example:** ```tomo ->> (./path/to/file.txt):relative(relative_to=(./path)) +>> (./path/to/file.txt).relative(relative_to=(./path)) = (./to/file.txt) ``` @@ -783,7 +783,7 @@ Nothing. **Example:** ```tomo -(./file.txt):remove() +(./file.txt).remove() ``` --- @@ -803,10 +803,10 @@ The resolved absolute path. **Example:** ```tomo ->> (~/foo):resolved() +>> (~/foo).resolved() = (/home/user/foo) ->> (./path/to/file.txt):resolved(relative_to=(/foo)) +>> (./path/to/file.txt).resolved(relative_to=(/foo)) = (/foo/path/to/file.txt) ``` @@ -829,7 +829,7 @@ Nothing. If a path does not exist, a failure will be raised. **Example:** ```tomo -(./file.txt):set_owner(owner="root", group="wheel") +(./file.txt).set_owner(owner="root", group="wheel") ``` --- @@ -849,10 +849,10 @@ A list of subdirectory paths. **Example:** ```tomo ->> (./directory):subdirectories() +>> (./directory).subdirectories() = [(./directory/subdir1), (./directory/subdir2)] ->> (./directory):subdirectories(include_hidden=yes) +>> (./directory).subdirectories(include_hidden=yes) = [(./directory/.git), (./directory/subdir1), (./directory/subdir2)] ``` @@ -873,11 +873,11 @@ A unique directory path after creating the directory. **Example:** ``` ->> created := (/tmp/my-dir.XXXXXX):unique_directory() +>> created := (/tmp/my-dir.XXXXXX).unique_directory() = (/tmp/my-dir-AwoxbM/) ->> created:is_directory() +>> created.is_directory() = yes -created:remove() +created.remove() ``` --- @@ -900,7 +900,7 @@ Nothing. **Example:** ```tomo -(./file.txt):write("Hello, world!") +(./file.txt).write("Hello, world!") ``` --- @@ -923,7 +923,7 @@ Nothing. **Example:** ```tomo -(./file.txt):write_bytes([104[B], 105[B]]) +(./file.txt).write_bytes([104[B], 105[B]]) ``` --- @@ -946,11 +946,11 @@ The path of the newly created unique file. **Example:** ```tomo ->> created := (./file-XXXXXX.txt):write_unique("Hello, world!") +>> created := (./file-XXXXXX.txt).write_unique("Hello, world!") = (./file-27QHtq.txt) ->> created:read() +>> created.read() = "Hello, world!" -created:remove() +created.remove() ``` --- @@ -973,9 +973,9 @@ The path of the newly created unique file. **Example:** ```tomo ->> created := (./file-XXXXXX.txt):write_unique_bytes([1[B], 2[B], 3[B]]) +>> created := (./file-XXXXXX.txt).write_unique_bytes([1[B], 2[B], 3[B]]) = (./file-27QHtq.txt) ->> created:read() +>> created.read() = [1[B], 2[B], 3[B]] -created:remove() +created.remove() ``` diff --git a/docs/pointers.md b/docs/pointers.md index f1bd1b5a..36cab2c1 100644 --- a/docs/pointers.md +++ b/docs/pointers.md @@ -94,12 +94,12 @@ For convenience, most operations that work on values can work with pointers to values implicitly. For example, if you have a struct type with a `.foo` field, you can use `ptr.foo` on a pointer to that struct type as well, without needing to use `ptr[].foo`. The same is true for array accesses like `ptr[i]` and method -calls like `ptr:reversed()`. +calls like `ptr.reversed()`. # Read-Only Views -In a small number of API methods (`array:first()`, `array:binary_search()`, -`array:sort()`, `array:sorted()`, and `array:heapify()`), the methods allow you +In a small number of API methods (`array.first()`, `array.binary_search()`, +`array.sort()`, `array.sorted()`, and `array.heapify()`), the methods allow you to provide custom comparison functions. However, for safety, we don't actually want the comparison methods to be able mutate the values inside of immutable array values. For implementation reasons, we can't pass the values themselves @@ -112,7 +112,7 @@ inside of any datastructures as elements or members. ```tomo nums := @[10, 20, 30] ->> nums:first(func(x:&Int): x / 2 == 10) +>> nums.first(func(x:&Int): x / 2 == 10) = 2 : Int? ``` diff --git a/docs/reductions.md b/docs/reductions.md index 959d9701..7aadd30b 100644 --- a/docs/reductions.md +++ b/docs/reductions.md @@ -80,7 +80,7 @@ maximum value _according to some feature_. = "aaaaa" # Get the number with the biggest absolute value: ->> (_max_:abs(): [1, -2, 3, -4])! +>> (_max_.abs(): [1, -2, 3, -4])! = -4 ``` @@ -96,6 +96,6 @@ while filtering out values or while applying a transformation: = 6 # Sum the primes between 1-100: ->> (+: i for i in 100 if i:is_prime())! +>> (+: i for i in 100 if i.is_prime())! = 1060 ``` diff --git a/docs/serialization.md b/docs/serialization.md index a1a38fdb..d63cb168 100644 --- a/docs/serialization.md +++ b/docs/serialization.md @@ -10,12 +10,12 @@ original value. ## Serializing -To serialize data, simply call the method `:serialized()` on any value and it +To serialize data, simply call the method `.serialized()` on any value and it will return an array of bytes that encode the value's data: ```tomo value := Int64(5) ->> serialized := value:serialized() +>> serialized := value.serialized() = [0x0A] : [Byte] ``` @@ -30,7 +30,7 @@ To deserialize data, you must provide its type explicitly using the syntax ```tomo i := 123 -bytes := i:serialized() +bytes := i.serialized() roundtripped := deserialize(bytes -> Int) >> roundtripped @@ -58,7 +58,7 @@ c := @Cycle("A") c.next = @Cycle("B", next=c) >> c = @Cycle(name="A", next=@Cycle(name="B", next=@~1)) ->> serialized := c:serialized() +>> serialized := c.serialized() = [0x02, 0x02, 0x41, 0x01, 0x04, 0x02, 0x42, 0x01, 0x02] : [Byte] >> roundtrip := DESERIALIZE(serialized):@Cycle = @Cycle(name="A", next=@Cycle(name="B", next=@~1)) : @Cycle diff --git a/docs/sets.md b/docs/sets.md index 023547dd..62351ed5 100644 --- a/docs/sets.md +++ b/docs/sets.md @@ -6,7 +6,7 @@ implemented using hash tables. ```tomo a := {10, 20, 30} b := {20, 30} ->> a:overlap(b) +>> a.overlap(b) = {20} ``` @@ -103,7 +103,7 @@ Nothing. **Example:** ```tomo ->> nums:add(42) +>> nums.add(42) ``` --- @@ -123,7 +123,7 @@ Nothing. **Example:** ```tomo ->> nums:add_all([1, 2, 3]) +>> nums.add_all([1, 2, 3]) ``` --- @@ -142,7 +142,7 @@ Nothing. **Example:** ```tomo ->> nums:clear() +>> nums.clear() ``` --- @@ -162,7 +162,7 @@ func has(set:{T}, item:T -> Bool) **Example:** ```tomo ->> {10, 20}:has(20) +>> {10, 20}.has(20) = yes ``` @@ -184,7 +184,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 ``` @@ -206,7 +206,7 @@ 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` @@ -224,7 +224,7 @@ A new set containing only items present in both sets. **Example:** ```tomo ->> {1, 2}:overlap({2, 3}) +>> {1, 2}.overlap({2, 3}) = {2} ``` @@ -245,7 +245,7 @@ Nothing. **Example:** ```tomo ->> nums:remove(42) +>> nums.remove(42) ``` --- @@ -265,7 +265,7 @@ Nothing. **Example:** ```tomo ->> nums:remove_all([1, 2, 3]) +>> nums.remove_all([1, 2, 3]) ``` --- @@ -285,7 +285,7 @@ A new set containing all items from both sets. **Example:** ```tomo ->> {1, 2}:with({2, 3}) +>> {1, 2}.with({2, 3}) = {1, 2, 3} ``` @@ -306,6 +306,6 @@ A new set containing items from the original set excluding those in the other se **Example:** ```tomo ->> {1, 2}:without({2, 3}) +>> {1, 2}.without({2, 3}) = {1} ``` diff --git a/docs/structs.md b/docs/structs.md index ce4f6ff5..f075f037 100644 --- a/docs/structs.md +++ b/docs/structs.md @@ -31,8 +31,8 @@ struct Foo(name:Text, age:Int): f.age += 1 ... my_foo := @Foo("Alice", 28) -my_foo:greet() -my_foo:get_older() +my_foo.greet() +my_foo.get_older() ``` Method calls work when the first argument is the struct type or a pointer to diff --git a/docs/tables.md b/docs/tables.md index 93ee3eb9..7a50c9dd 100644 --- a/docs/tables.md +++ b/docs/tables.md @@ -102,7 +102,7 @@ is non-optional (because a value will always be present). ## Setting Values You can assign a new key/value mapping or overwrite an existing one using -`:set(key, value)` or an `=` assignment statement: +`.set(key, value)` or an `=` assignment statement: ```tomo t := {"A"=1, "B"=2} @@ -177,8 +177,8 @@ Nothing. **Example:** ```tomo >> t := {"A"=1} -t:bump("A") -t:bump("B", 10) +t.bump("A") +t.bump("B", 10) >> t = {"A"=2, "B"=10} ``` @@ -199,7 +199,7 @@ Nothing. **Example:** ```tomo ->> t:clear() +>> t.clear() ``` --- @@ -221,16 +221,16 @@ The value associated with the key or `none` if the key is not found. **Example:** ```tomo >> t := {"A"=1, "B"=2} ->> t:get("A") +>> t.get("A") = 1? ->> t:get("????") +>> t.get("????") = none ->> t:get("A")! +>> t.get("A")! = 1 ->> t:get("????") or 0 +>> t.get("????") or 0 = 0 ``` @@ -251,9 +251,9 @@ func has(t:{K=V}, key: K -> Bool) **Example:** ```tomo ->> {"A"=1, "B"=2}:has("A") +>> {"A"=1, "B"=2}.has("A") = yes ->> {"A"=1, "B"=2}:has("xxx") +>> {"A"=1, "B"=2}.has("xxx") = no ``` @@ -275,7 +275,7 @@ Nothing. **Example:** ```tomo t := {"A"=1, "B"=2} -t:remove("A") +t.remove("A") >> t = {"B"=2} ``` @@ -299,7 +299,7 @@ Nothing. **Example:** ```tomo t := {"A"=1, "B"=2} -t:set("C", 3) +t.set("C", 3) >> t = {"A"=1, "B"=2, "C"=3} ``` diff --git a/docs/text.md b/docs/text.md index fd79fdbd..f0665762 100644 --- a/docs/text.md +++ b/docs/text.md @@ -245,7 +245,7 @@ several joining modifiers attached to it, that text has a length of 1. Iteration is *not* supported for text. It is rarely ever the case that you will need to iterate over text, but if you do, you can iterate over the length of the text and retrieve 1-wide slices. Alternatively, you can split the text into -its constituent grapheme clusters with `text:split()` and iterate over those. +its constituent grapheme clusters with `text.split()` and iterate over those. ### Equality, Comparison, and Hashing @@ -319,7 +319,7 @@ A C-style string (`CString`) representing the text. **Example:** ```tomo ->> "Hello":as_c_string() +>> "Hello".as_c_string() = CString("Hello") ``` @@ -343,7 +343,7 @@ indices are counted from the back of the text, so `-1` means the last cluster, **Example:** ```tomo ->> "Amélie":at(3) +>> "Amélie".at(3) = "é" ``` @@ -362,7 +362,7 @@ func by_line(text: Text -> func(->Text?)) **Returns:** An iterator function that returns one line at a time, until it runs out and returns `none`. **Note:** this function ignores a trailing newline if there is -one. If you don't want this behavior, use `text:by_split($/{1 nl}/)` instead. +one. If you don't want this behavior, use `text.by_split($/{1 nl}/)` instead. **Example:** ```tomo @@ -370,7 +370,7 @@ text := " line one line two " -for line in text:by_line(): +for line in text.by_line(): # Prints: "line one" then "line two": say(line) ``` @@ -398,7 +398,7 @@ delimiter (the default) will iterate over single grapheme clusters in the text. **Example:** ```tomo text := "one,two,three" -for chunk in text:by_split(","): +for chunk in text.by_split(","): # Prints: "one" then "two" then "three": say(chunk) ``` @@ -425,7 +425,7 @@ given delimiter characters, until it runs out and returns `none`. **Example:** ```tomo text := "one,two,;,three" -for chunk in text:by_split_any(",;"): +for chunk in text.by_split_any(",;"): # Prints: "one" then "two" then "three": say(chunk) ``` @@ -447,7 +447,7 @@ An array of bytes (`[Byte]`) representing the text in UTF8 encoding. **Example:** ```tomo ->> "Amélie":bytes() +>> "Amélie".bytes() = [65[B], 109[B], 195[B], 169[B], 108[B], 105[B], 101[B]] : [Byte] ``` @@ -470,11 +470,11 @@ func caseless_equals(a: Text, b:Text, language:Text = "C" -> Bool) **Example:** ```tomo ->> "A":caseless_equals("a") +>> "A".caseless_equals("a") = yes # Turkish lowercase "I" is "ı" (dotless I), not "i" ->> "I":caseless_equals("i", language="tr_TR") +>> "I".caseless_equals("i", language="tr_TR") = no ``` @@ -494,7 +494,7 @@ An array of codepoint names (`[Text]`). **Example:** ```tomo ->> "Amélie":codepoint_names() +>> "Amélie".codepoint_names() = ["LATIN CAPITAL LETTER A", "LATIN SMALL LETTER M", "LATIN SMALL LETTER E WITH ACUTE", "LATIN SMALL LETTER L", "LATIN SMALL LETTER I", "LATIN SMALL LETTER E"] ``` @@ -515,7 +515,7 @@ func ends_with(text: Text, suffix: Text -> Bool) **Example:** ```tomo ->> "hello world":ends_with("world") +>> "hello world".ends_with("world") = yes ``` @@ -539,10 +539,10 @@ the length of the text. **Example:** ```tomo ->> "hello":from(2) +>> "hello".from(2) = "ello" ->> "hello":from(-2) +>> "hello".from(-2) = "lo" ``` @@ -655,9 +655,9 @@ func has(text: Text, target: Text -> Bool) **Example:** ```tomo ->> "hello world":has("wo") +>> "hello world".has("wo") = yes ->> "hello world":has("xxx") +>> "hello world".has("xxx") = no ``` @@ -678,7 +678,7 @@ A single `Text` value with the pieces joined by the glue. **Example:** ```tomo ->> ", ":join(["one", "two", "three"]) +>> ", ".join(["one", "two", "three"]) = "one, two, three" ``` @@ -703,9 +703,9 @@ reach the exact desired length. **Example:** ```tomo ->> "x":middle_pad(6) +>> "x".middle_pad(6) = " x " ->> "x":middle_pad(10, "ABC") +>> "x".middle_pad(10, "ABC") = "ABCAxABCAB" ``` @@ -730,9 +730,9 @@ exact desired length. **Example:** ```tomo ->> "x":left_pad(5) +>> "x".left_pad(5) = " x" ->> "x":left_pad(5, "ABC") +>> "x".left_pad(5, "ABC") = "ABCAx" ``` @@ -753,15 +753,15 @@ An array of substrings resulting from the split. **Example:** ```tomo ->> "one$(\n)two$(\n)three":lines() +>> "one$(\n)two$(\n)three".lines() = ["one", "two", "three"] ->> "one$(\n)two$(\n)three$(\n)":lines() +>> "one$(\n)two$(\n)three$(\n)".lines() = ["one", "two", "three"] ->> "one$(\n)two$(\n)three$(\n\n)":lines() +>> "one$(\n)two$(\n)three$(\n\n)".lines() = ["one", "two", "three", ""] ->> "one$(\r\n)two$(\r\n)three$(\r\n)":lines() +>> "one$(\r\n)two$(\r\n)three$(\r\n)".lines() = ["one", "two", "three"] ->> "":lines() +>> "".lines() = [] ``` @@ -782,10 +782,10 @@ The lowercase version of the text. **Example:** ```tomo ->> "AMÉLIE":lower() +>> "AMÉLIE".lower() = "amélie" ->> "I":lower(language="tr_TR") +>> "I".lower(language="tr_TR") >> "ı" ``` @@ -807,7 +807,7 @@ The text formatted as a quoted text. **Example:** ```tomo ->> "one$(\n)two":quoted() +>> "one$(\n)two".quoted() = "\"one\\ntwo\"" ``` @@ -828,7 +828,7 @@ The text repeated the given number of times. **Example:** ```tomo ->> "Abc":repeat(3) +>> "Abc".repeat(3) = "AbcAbcAbc" ``` @@ -850,7 +850,7 @@ The text with occurrences of the target replaced. **Example:** ```tomo ->> "Hello world":replace("world", "there") +>> "Hello world".replace("world", "there") = "Hello there" ``` @@ -870,7 +870,7 @@ A reversed version of the text. **Example:** ```tomo ->> "Abc":reversed() +>> "Abc".reversed() = "cbA" ``` @@ -895,9 +895,9 @@ exact desired length. **Example:** ```tomo ->> "x":right_pad(5) +>> "x".right_pad(5) = "x " ->> "x":right_pad(5, "ABC") +>> "x".right_pad(5, "ABC") = "xABCA" ``` @@ -922,13 +922,13 @@ the text. **Example:** ```tomo ->> "hello":slice(2, 3) +>> "hello".slice(2, 3) = "el" ->> "hello":slice(to=-2) +>> "hello".slice(to=-2) = "hell" ->> "hello":slice(from=2) +>> "hello".slice(from=2) = "ello" ``` @@ -951,10 +951,10 @@ An array of subtexts resulting from the split. **Example:** ```tomo ->> "one,two,,three":split(",") +>> "one,two,,three".split(",") = ["one", "two", "", "three"] ->> "abc":split() +>> "abc".split() = ["a", "b", "c"] ``` @@ -978,7 +978,7 @@ An array of subtexts resulting from the split. **Example:** ```tomo ->> "one, two,,three":split_any(", ") +>> "one, two,,three".split_any(", ") = ["one", "two", "three"] ``` @@ -999,7 +999,7 @@ func starts_with(text: Text, prefix: Text -> Bool) **Example:** ```tomo ->> "hello world":starts_with("hello") +>> "hello world".starts_with("hello") = yes ``` @@ -1020,11 +1020,11 @@ The text in title case. **Example:** ```tomo ->> "amélie":title() +>> "amélie".title() = "Amélie" # In Turkish, uppercase "i" is "İ" ->> "i":title(language="tr_TR") +>> "i".title(language="tr_TR") = "İ" ``` @@ -1048,10 +1048,10 @@ the text. **Example:** ```tomo ->> "goodbye":to(3) +>> "goodbye".to(3) = "goo" ->> "goodbye":to(-2) +>> "goodbye".to(-2) = "goodby" ``` @@ -1077,7 +1077,7 @@ replacement text. **Example:** ```tomo ->> "A <tag> & an amperand":translate({ +>> "A <tag> & an amperand".translate({ "&" = "&", "<" = "<", ">" = ">", @@ -1106,13 +1106,13 @@ The text without the trim characters at either end. **Example:** ```tomo ->> " x y z $(\n)":trim() +>> " x y z $(\n)".trim() = "x y z" ->> "one,":trim(",") +>> "one,".trim(",") = "one" ->> " xyz ":trim(right=no) +>> " xyz ".trim(right=no) = "xyz " ``` @@ -1133,11 +1133,11 @@ The uppercase version of the text. **Example:** ```tomo ->> "amélie":upper() +>> "amélie".upper() = "AMÉLIE" # In Turkish, uppercase "i" is "İ" ->> "i":upper(language="tr_TR") +>> "i".upper(language="tr_TR") = "İ" ``` @@ -1157,7 +1157,7 @@ An array of 32-bit integer Unicode code points (`[Int32]`). **Example:** ```tomo ->> "Amélie":utf32_codepoints() +>> "Amélie".utf32_codepoints() = [65[32], 109[32], 233[32], 108[32], 105[32], 101[32]] : [Int32] ``` @@ -1182,9 +1182,9 @@ An integer representing the display width of the text. **Example:** ```tomo ->> "Amélie":width() +>> "Amélie".width() = 6 ->> "🤠":width() +>> "🤠".width() = 2 ``` @@ -1206,9 +1206,9 @@ prefix is not present. **Example:** ```tomo ->> "foo:baz":without_prefix("foo:") +>> "foo:baz".without_prefix("foo:") = "baz" ->> "qux":without_prefix("foo:") +>> "qux".without_prefix("foo:") = "qux" ``` @@ -1230,8 +1230,8 @@ suffix is not present. **Example:** ```tomo ->> "baz.foo":without_suffix(".foo") +>> "baz.foo".without_suffix(".foo") = "baz" ->> "qux":without_suffix(".foo") +>> "qux".without_suffix(".foo") = "qux" ``` |
