Explorar o código

Use new curly escape in prelude modules

Mads Møller Jensen hai 6 meses
pai
achega
004770e4d9

+ 14 - 4
book/src/list-functions-strings.md

@@ -114,9 +114,14 @@ fn str_append(a: String, b: String) -> String
 <details>
 <summary>Examples</summary>
 
-<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code"  onclick=" window.open('https://numbat.dev/?q=%22Numbat%22%20%7C%3E%20str%5Fappend%28%22%21%22%29')""></button></div><code class="language-nbt hljs numbat">"Numbat" |> str_append("!")
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code"  onclick=" window.open('https://numbat.dev/?q=%22%21%22%20%7C%3E%20str%5Fappend%28%22Numbat%22%29')""></button></div><code class="language-nbt hljs numbat">"!" |> str_append("Numbat")
 
-    = "!Numbat"    [String]
+    = "Numbat!"    [String]
+</code></pre>
+
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code"  onclick=" window.open('https://numbat.dev/?q=str%5Fappend%28%22Numbat%22%2C%20%22%21%22%29')""></button></div><code class="language-nbt hljs numbat">str_append("Numbat", "!")
+
+    = "Numbat!"    [String]
 </code></pre>
 
 </details>
@@ -131,9 +136,14 @@ fn str_prepend(a: String, b: String) -> String
 <details>
 <summary>Examples</summary>
 
-<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code"  onclick=" window.open('https://numbat.dev/?q=%22%21%22%20%7C%3E%20str%5Fprepend%28%22Numbat%22%29')""></button></div><code class="language-nbt hljs numbat">"!" |> str_prepend("Numbat")
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code"  onclick=" window.open('https://numbat.dev/?q=%22Numbat%22%20%7C%3E%20str%5Fprepend%28%22%21%22%29')""></button></div><code class="language-nbt hljs numbat">"Numbat" |> str_prepend("!")
+
+    = "Numbat!"    [String]
+</code></pre>
+
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code"  onclick=" window.open('https://numbat.dev/?q=str%5Fprepend%28%22%21%22%2C%20%22Numbat%22%29')""></button></div><code class="language-nbt hljs numbat">str_prepend("!", "Numbat")
 
-    = "!Numbat"    [String]
+    = "Numbat!"    [String]
 </code></pre>
 
 </details>

+ 2 - 2
numbat/modules/core/functions.nbt

@@ -12,13 +12,13 @@ fn id<A>(x: A) -> A = x
 fn abs<T: Dim>(x: T) -> T
 
 @name("Square root")
-@description("Return the square root $\\sqrt\{x\}$ of the input: `sqrt(121 m^2) = 11 m`.")
+@description("Return the square root $\\sqrt{{x}}$ of the input: `sqrt(121 m^2) = 11 m`.")
 @url("https://en.wikipedia.org/wiki/Square_root")
 @example("sqrt(4 are) -> m")
 fn sqrt<D: Dim>(x: D^2) -> D = x^(1/2)
 
 @name("Cube root")
-@description("Return the cube root $\\sqrt[3]\{x\}$ of the input: `cbrt(8 m^3) = 2 m`.")
+@description("Return the cube root $\\sqrt[3]{{x}}$ of the input: `cbrt(8 m^3) = 2 m`.")
 @url("https://en.wikipedia.org/wiki/Cube_root")
 @example("cbrt(8 L) -> cm")
 fn cbrt<D: Dim>(x: D^3) -> D = x^(1/3)

+ 4 - 2
numbat/modules/core/strings.nbt

@@ -27,11 +27,13 @@ fn lowercase(s: String) -> String
 fn uppercase(s: String) -> String
 
 @description("Concatenate two strings")
-@example("\"Numbat\" |> str_append(\"!\")")
+@example("\"!\" |> str_append(\"Numbat\")")
+@example("str_append(\"Numbat\", \"!\")")
 fn str_append(a: String, b: String) -> String = "{a}{b}"
 
 @description("Concatenate two strings")
-@example("\"!\" |> str_prepend(\"Numbat\")")
+@example("\"Numbat\" |> str_prepend(\"!\")")
+@example("str_prepend(\"!\", \"Numbat\")")
 fn str_prepend(a: String, b: String) -> String = "{b}{a}"
 
 fn _str_find(needle: String, index: Scalar, haystack: String) -> Scalar =

+ 3 - 3
numbat/modules/math/combinatorics.nbt

@@ -35,7 +35,7 @@ fn binom(n: Scalar, k: Scalar) -> Scalar =
     falling_factorial(n, k) / k!
 
 @name("Fibonacci numbers")
-@description("The nth Fibonacci number, where n is a nonnegative integer. The Fibonacci sequence is given by $F_0=0$, $F_1=1$, and $F_n=F_\{n-1\}+F_\{n-2\}$ for $n≥2$. The first several elements, starting with $n=0$, are $0, 1, 1, 2, 3, 5, 8, 13$.")
+@description("The nth Fibonacci number, where n is a nonnegative integer. The Fibonacci sequence is given by $F_0=0$, $F_1=1$, and $F_n=F_{{n-1}}+F_{{n-2}}$ for $n≥2$. The first several elements, starting with $n=0$, are $0, 1, 1, 2, 3, 5, 8, 13$.")
 @url("https://en.wikipedia.org/wiki/Fibonacci_sequence")
 @example("fibonacci(5)")
 fn fibonacci(n: Scalar) -> Scalar =
@@ -47,7 +47,7 @@ fn fibonacci(n: Scalar) -> Scalar =
       where phi = (1+sqrt(5))/2
 
 @name("Lucas numbers")
-@description("The nth Lucas number, where n is a nonnegative integer. The Lucas sequence is given by $L_0=2$, $L_1=1$, and $L_n=L_\{n-1\}+L_\{n-2\}$ for $n≥2$. The first several elements, starting with $n=0$, are $2, 1, 3, 4, 7, 11, 18, 29$.")
+@description("The nth Lucas number, where n is a nonnegative integer. The Lucas sequence is given by $L_0=2$, $L_1=1$, and $L_n=L_{{n-1}}+L_{{n-2}}$ for $n≥2$. The first several elements, starting with $n=0$, are $2, 1, 3, 4, 7, 11, 18, 29$.")
 @url("https://en.wikipedia.org/wiki/Lucas_number")
 @example("lucas(5)")
 fn lucas(n: Scalar) -> Scalar =
@@ -59,7 +59,7 @@ fn lucas(n: Scalar) -> Scalar =
       where phi = (1+sqrt(5))/2
 
 @name("Catalan numbers")
-@description("The nth Catalan number, where n is a nonnegative integer. The Catalan sequence is given by $C_n=\frac\{1\}\{n+1\}\binom\{2n\}\{n\}=\binom\{2n\}\{n\}-\binom\{2n\}\{n+1\}$. The first several elements, starting with $n=0$, are $1, 1, 2, 5, 14, 42, 132, 429$.")
+@description("The nth Catalan number, where n is a nonnegative integer. The Catalan sequence is given by $C_n=\frac{{1}}{{n+1}}\binom{{2n}}{{n}}=\binom{{2n}}{{n}}-\binom{{2n}}{{n+1}}$. The first several elements, starting with $n=0$, are $1, 1, 2, 5, 14, 42, 132, 429$.")
 @url("https://en.wikipedia.org/wiki/Catalan_number")
 @example("catalan(5)")
 fn catalan(n: Scalar) -> Scalar =

+ 3 - 3
numbat/modules/math/geometry.nbt

@@ -1,11 +1,11 @@
 use core::functions
 use math::constants
 
-@description("The length of the hypotenuse of a right-angled triangle $\\sqrt\{x^2+y^2\}$.")
+@description("The length of the hypotenuse of a right-angled triangle $\\sqrt{{x^2+y^2}}$.")
 @example("hypot2(3 m, 4 m)")
 fn hypot2<T: Dim>(x: T, y: T) -> T = sqrt(x^2 + y^2)
 
-@description("The Euclidean norm of a 3D vector $\\sqrt\{x^2+y^2+z^2\}$.")
+@description("The Euclidean norm of a 3D vector $\\sqrt{{x^2+y^2+z^2}}$.")
 @example("hypot3(8, 9, 12)")
 fn hypot3<T: Dim>(x: T, y: T, z: T) -> T = sqrt(x^2 + y^2 + z^2)
 
@@ -22,5 +22,5 @@ fn circle_circumference<L: Dim>(radius: L) -> L = 2 π × radius
 @description("The surface area of a sphere, $4\\pi r^2$.")
 fn sphere_area<L: Dim>(radius: L) -> L^2 = 4 π × radius^2
 
-@description("The volume of a sphere, $\\frac\{4\}\{3\}\\pi r^3$.")
+@description("The volume of a sphere, $\\frac{{4}}{{3}}\\pi r^3$.")
 fn sphere_volume<L: Dim>(radius: L) -> L^3 = 4/3 × π × radius^3