From 03fb18356a4c055a2ccc29734fc3823aaf588a98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Fri, 27 Jan 2023 23:39:49 +0100 Subject: [PATCH 1/3] Docs: Add refs to `Number` collection convenience constructors --- src/number.cr | 23 +++++++++++++++++++++++ src/slice.cr | 3 ++- src/static_array.cr | 3 ++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/number.cr b/src/number.cr index 62177e78d89c..e7b21225ee7b 100644 --- a/src/number.cr +++ b/src/number.cr @@ -71,6 +71,13 @@ struct Number # ints = Int64[1, 2, 3] # ints.class # => Array(Int64) # ``` + # + # This is equivalent to an array literal of the same item type: + # + # ``` + # Int64[1, 2, 3, 4] # : Array(Int64) + # [1, 2, 3, 4] of Int64 # : Array(Int64) + # ``` macro [](*nums) Array({{@type}}).build({{nums.size}}) do |%buffer| {% for num, i in nums %} @@ -92,6 +99,14 @@ struct Number # ints = Int64.slice(1, 2, 3) # ints.class # => Slice(Int64) # ``` + # + # This is a convenvenient alternative to `Slice.[]` for designating a + # specific item type which also considers autocasting. + # + # ``` + # Int64.slice(1, 2, 3, 4) # : Slice(Int64) + # Slice[1_i64, 2_i64, 3_i64, 4_i64] # : Slice(Int64) + # ``` macro slice(*nums, read_only = false) %slice = Slice({{@type}}).new({{nums.size}}, read_only: {{read_only}}) {% for num, i in nums %} @@ -110,6 +125,14 @@ struct Number # ints = Int64.static_array(1, 2, 3) # ints.class # => StaticArray(Int64, 3) # ``` + # + # This is a convenvenient alternative to `StaticArray.[]` for designating a + # specific item type which also considers autocasting. + # + # ``` + # Int64.static_array(1, 2, 3, 4) # : StaticArray(Int64) + # StaticArray[1_i64, 2_i64, 3_i64, 4_i64] # : StaticArray(Int64) + # ``` macro static_array(*nums) %array = uninitialized StaticArray({{@type}}, {{nums.size}}) {% for num, i in nums %} diff --git a/src/slice.cr b/src/slice.cr index ebdd7c5f4cc8..4a49f77b97e6 100644 --- a/src/slice.cr +++ b/src/slice.cr @@ -29,7 +29,8 @@ struct Slice(T) # If `T` is a `Number` then this is equivalent to # `Number.slice` (numbers will be coerced to the type `T`) # - # See also: `Number.slice`. + # * `Number.slice` is a convenient alternative for designating a + # specific numerical item type. macro [](*args, read_only = false) # TODO: there should be a better way to check this, probably # asking if @type was instantiated or if T is defined diff --git a/src/static_array.cr b/src/static_array.cr index 714e3368a187..ee502fb63035 100644 --- a/src/static_array.cr +++ b/src/static_array.cr @@ -47,7 +47,8 @@ struct StaticArray(T, N) # ary.class # => StaticArray(Char | Int32, 2) # ``` # - # See also: `Number.static_array`. + # * `Number.static_array` is a convenient alternative for designating a + # specific numerical item type. macro [](*args) %array = uninitialized StaticArray(typeof({{*args}}), {{args.size}}) {% for arg, i in args %} From f43ae2230656b81485161d7cb304700dc4460b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Tue, 31 Jan 2023 21:53:08 +0100 Subject: [PATCH 2/3] Update src/number.cr --- src/number.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/number.cr b/src/number.cr index e7b21225ee7b..0153dd9d29d8 100644 --- a/src/number.cr +++ b/src/number.cr @@ -72,7 +72,7 @@ struct Number # ints.class # => Array(Int64) # ``` # - # This is equivalent to an array literal of the same item type: + # This is similar to an array literal of the same item type: # # ``` # Int64[1, 2, 3, 4] # : Array(Int64) From 28a52a82832cb4a27c800591f42cef24379d6247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Tue, 31 Jan 2023 22:02:52 +0100 Subject: [PATCH 3/3] Fix type --- src/number.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/number.cr b/src/number.cr index 0153dd9d29d8..9aae19e1eb8a 100644 --- a/src/number.cr +++ b/src/number.cr @@ -100,7 +100,7 @@ struct Number # ints.class # => Slice(Int64) # ``` # - # This is a convenvenient alternative to `Slice.[]` for designating a + # This is a convenient alternative to `Slice.[]` for designating a # specific item type which also considers autocasting. # # ```