From 5f15b5939cec686ce56c3f44794c4606130365ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Wed, 5 Jun 2024 15:58:31 +0200 Subject: [PATCH 1/6] Make snippets interactive with annotations --- code-samples/as-operator-array-literal.pony | 5 +++-- docs/expressions/as.md | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/code-samples/as-operator-array-literal.pony b/code-samples/as-operator-array-literal.pony index 00c23c4a..7fd5de16 100644 --- a/code-samples/as-operator-array-literal.pony +++ b/code-samples/as-operator-array-literal.pony @@ -5,5 +5,6 @@ actor Main new create(env: Env) => foo([as U32: 1; 2; 3]) - // the compiler would complain about this: - // foo([1; 2; 3]) \ No newline at end of file + // Try changing it to + // foo([1; 2; 3]) + // the compiler would complain about this: \ No newline at end of file diff --git a/docs/expressions/as.md b/docs/expressions/as.md index 08838c91..630e6402 100644 --- a/docs/expressions/as.md +++ b/docs/expressions/as.md @@ -60,7 +60,7 @@ The `as` operator can also be used to tell the compiler what type to use for the For example, in the case of the following program, the method `foo` can take either an `Array[U32] ref` or an `Array[U64] ref` as an argument. If a literal array is passed as an argument to the method and no type is specified then the compiler cannot deduce the correct one because there are two equally valid ones. -```pony +```{ .pony .annotate } --8<-- "as-operator-array-literal.pony" ``` From 47f60cf28657348c06678e219edf9221f9d910dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Wed, 5 Jun 2024 16:07:33 +0200 Subject: [PATCH 2/6] Reference annotation content --- code-samples/as-operator-array-literal.pony | 4 +--- docs/expressions/as.md | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/code-samples/as-operator-array-literal.pony b/code-samples/as-operator-array-literal.pony index 7fd5de16..e2c6b13f 100644 --- a/code-samples/as-operator-array-literal.pony +++ b/code-samples/as-operator-array-literal.pony @@ -5,6 +5,4 @@ actor Main new create(env: Env) => foo([as U32: 1; 2; 3]) - // Try changing it to - // foo([1; 2; 3]) - // the compiler would complain about this: \ No newline at end of file + // (1) \ No newline at end of file diff --git a/docs/expressions/as.md b/docs/expressions/as.md index 630e6402..49cbb0ea 100644 --- a/docs/expressions/as.md +++ b/docs/expressions/as.md @@ -64,4 +64,10 @@ For example, in the case of the following program, the method `foo` can take eit --8<-- "as-operator-array-literal.pony" ``` + + +1. Try changing it to + // foo([1; 2; 3]) + // the compiler would complain about this: + The requested type must be a valid type for the items in the array. Since these types are checked at compile time they are guaranteed to work, so there is no need for the programmer to handle an error condition. From a1932b302e46c4ca820b10ea339b5a22dc59d7ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Wed, 5 Jun 2024 16:08:45 +0200 Subject: [PATCH 3/6] Spacing --- docs/expressions/as.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/expressions/as.md b/docs/expressions/as.md index 49cbb0ea..1d534d29 100644 --- a/docs/expressions/as.md +++ b/docs/expressions/as.md @@ -64,10 +64,8 @@ For example, in the case of the following program, the method `foo` can take eit --8<-- "as-operator-array-literal.pony" ``` - - -1. Try changing it to +1. Try changing it to: // foo([1; 2; 3]) - // the compiler would complain about this: + // the compiler would complain about this The requested type must be a valid type for the items in the array. Since these types are checked at compile time they are guaranteed to work, so there is no need for the programmer to handle an error condition. From 036d65e6c006f3e5402d46605d00d9786fd6c206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Wed, 5 Jun 2024 16:10:44 +0200 Subject: [PATCH 4/6] Formatting --- docs/expressions/as.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/expressions/as.md b/docs/expressions/as.md index 1d534d29..e98b5b65 100644 --- a/docs/expressions/as.md +++ b/docs/expressions/as.md @@ -64,8 +64,8 @@ For example, in the case of the following program, the method `foo` can take eit --8<-- "as-operator-array-literal.pony" ``` -1. Try changing it to: - // foo([1; 2; 3]) +1. Try changing it to:\ + `foo([1; 2; 3])`\ // the compiler would complain about this The requested type must be a valid type for the items in the array. Since these types are checked at compile time they are guaranteed to work, so there is no need for the programmer to handle an error condition. From 952d6b94663f7b2c9f89728fa9b2cbed19d3a800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Wed, 5 Jun 2024 16:15:33 +0200 Subject: [PATCH 5/6] Fix formatting --- docs/expressions/as.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/expressions/as.md b/docs/expressions/as.md index e98b5b65..0d551948 100644 --- a/docs/expressions/as.md +++ b/docs/expressions/as.md @@ -64,8 +64,8 @@ For example, in the case of the following program, the method `foo` can take eit --8<-- "as-operator-array-literal.pony" ``` -1. Try changing it to:\ - `foo([1; 2; 3])`\ - // the compiler would complain about this +1. Try changing it to: + `foo([1; 2; 3])` + The compiler will complain about this The requested type must be a valid type for the items in the array. Since these types are checked at compile time they are guaranteed to work, so there is no need for the programmer to handle an error condition. From 1206a48fae6103095eb638520a77b2c5b71e26ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Wed, 5 Jun 2024 16:18:53 +0200 Subject: [PATCH 6/6] Strip annotation comment --- code-samples/as-operator-array-literal.pony | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code-samples/as-operator-array-literal.pony b/code-samples/as-operator-array-literal.pony index e2c6b13f..74c08a22 100644 --- a/code-samples/as-operator-array-literal.pony +++ b/code-samples/as-operator-array-literal.pony @@ -5,4 +5,4 @@ actor Main new create(env: Env) => foo([as U32: 1; 2; 3]) - // (1) \ No newline at end of file + // (1)! \ No newline at end of file