diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-02-19 18:50:50 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-02-19 18:50:50 -0500 |
| commit | 058a028aef6f056a31d1e9a09fa83d498c553b78 (patch) | |
| tree | 21f0be237338d13ebc9380aee2a1db5afaad53d6 /docs/langs.md | |
| parent | 29849d145787fac5df454d9314c98570488045ce (diff) | |
Switch to langs using constructors
Diffstat (limited to 'docs/langs.md')
| -rw-r--r-- | docs/langs.md | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/docs/langs.md b/docs/langs.md index 37141bdc..96c026f1 100644 --- a/docs/langs.md +++ b/docs/langs.md @@ -10,7 +10,7 @@ where a different type of string is needed. ```tomo lang HTML: - func escape(t:Text -> HTML): + func HTML(t:Text -> HTML): t = t:replace_all({ $/&/ = "&", $/</ = "<", @@ -57,8 +57,8 @@ Hello <script>alert('pwned')</script>! How are you? ``` This works because the compiler checks for a function in the HTML namespace -called `HTML.escape` or any method that starts with `HTML.escape_` that takes a -`Text` argument and returns an `HTML` value. When performing interpolation, the +that was defined with the name `HTML` that takes a `Text` argument and returns +an `HTML` value (a constructor). When performing interpolation, the interpolation will only succeed if such a function exists and it will apply that function to the value before concatenating it. @@ -74,7 +74,7 @@ instead of building a global function called `execute()` that takes a ```tomo lang Sh: - func escape(text:Text -> Sh): + func Sh(text:Text -> Sh): return Sh.without_escaping("'" ++ text:replace($/'/, "''") ++ "'") func execute(sh:Sh -> Text): |
