From 45bbfa0ebd10fa5b16273eb3bb633ca100236e34 Mon Sep 17 00:00:00 2001 From: Araozu Date: Mon, 23 Oct 2023 20:39:34 -0500 Subject: [PATCH] Changes --- md/learn/classes/definition.md | 10 +++++----- md/learn/classes/interfaces.md | 2 +- md/learn/classes/magic.md | 6 +++++- md/learn/classes/static.md | 19 ++++++++++++++----- md/learn/flow-control/loops.md | 5 +++-- md/learn/functions/declaration.md | 15 ++++++++++++++- md/learn/functions/higher-order.md | 3 +++ static/js/prism.thp.js | 2 +- 8 files changed, 46 insertions(+), 16 deletions(-) diff --git a/md/learn/classes/definition.md b/md/learn/classes/definition.md index a591827..7ffec60 100644 --- a/md/learn/classes/definition.md +++ b/md/learn/classes/definition.md @@ -31,8 +31,8 @@ class SimpleClass // Properties are private by default var String? name; - // Made public with `public` - public var String? surname; + // Made public with `pub` + pub var String? surname; // Methods are private by default fun display_name($) @@ -41,7 +41,7 @@ class SimpleClass print($name) } - public fun get_name($) -> String? + pub fun get_name($) -> String? { $name } @@ -61,7 +61,7 @@ Kotlin style ```thp class Cat(val String name) { - public fun get_name($) -> String + pub fun get_name($) -> String { $name } @@ -78,7 +78,7 @@ Kotlin style ```thp class Animal(val String name) { - public fun say_name($) + pub fun say_name($) { print($name) } diff --git a/md/learn/classes/interfaces.md b/md/learn/classes/interfaces.md index 1fca19e..ec4242c 100644 --- a/md/learn/classes/interfaces.md +++ b/md/learn/classes/interfaces.md @@ -11,7 +11,7 @@ interface Serializable -class Cat -> Serializable, +class Cat -> Serializable { pub fun Serializable($) -> String { diff --git a/md/learn/classes/magic.md b/md/learn/classes/magic.md index df03c7b..640d376 100644 --- a/md/learn/classes/magic.md +++ b/md/learn/classes/magic.md @@ -1,6 +1,6 @@ # Magic methods -Are always public +Don't get special treatment. ```thp @@ -14,3 +14,7 @@ class Cat ``` + +```thp + +``` diff --git a/md/learn/classes/static.md b/md/learn/classes/static.md index 7691bd1..f310b5a 100644 --- a/md/learn/classes/static.md +++ b/md/learn/classes/static.md @@ -4,7 +4,13 @@ ## Class constants ```thp -static Cat { +class Cat +{ + // Stateful code +} + +static Cat +{ const CONSTANT = "constant value" } @@ -18,8 +24,10 @@ aka. plain, old functions ```thp -static Cat { - fun static_method() -> Int { +static Cat +{ + fun static_method() -> Int + { // ... } } @@ -34,8 +42,9 @@ aka. global variables ```thp -static Cat { - public var access_count = 0 +static Cat +{ + pub var access_count = 0 } print(Cat::access_count) // 0 diff --git a/md/learn/flow-control/loops.md b/md/learn/flow-control/loops.md index 709cf07..65ce386 100644 --- a/md/learn/flow-control/loops.md +++ b/md/learn/flow-control/loops.md @@ -58,7 +58,7 @@ while index < colors.size() ## Infinite loop -Basically Rust's loop. +Basically Rust*'s loop. ```thp loop @@ -72,7 +72,8 @@ loop } ``` - +* Rust is a trademark of the Rust Foundation. THP is not affiliated, +endorsed or supported by the Rust Foundation. diff --git a/md/learn/functions/declaration.md b/md/learn/functions/declaration.md index 4a05774..b14935a 100644 --- a/md/learn/functions/declaration.md +++ b/md/learn/functions/declaration.md @@ -78,7 +78,20 @@ fun html_special_chars( html_special_chars(input, double_encode: false) ``` - +## Named arguments with different names + +```thp +fun replace( + String in: input, + String each: pattern, + String with: replacement, +) -> String +{ + // Use input, pattern and replacement +} + +replace(each: " ", in: "my name", with: "-") +``` diff --git a/md/learn/functions/higher-order.md b/md/learn/functions/higher-order.md index d28394b..4ae4bd4 100644 --- a/md/learn/functions/higher-order.md +++ b/md/learn/functions/higher-order.md @@ -17,6 +17,9 @@ fun map[A, B](Array[A] input, (A) -> B function) -> Array[B] fun generate_generator() -> () -> Int { // code... + return fun() { + 322 + } } diff --git a/static/js/prism.thp.js b/static/js/prism.thp.js index 6037491..caac184 100644 --- a/static/js/prism.thp.js +++ b/static/js/prism.thp.js @@ -15,7 +15,7 @@ Prism.languages.thp = { pattern: /(["])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/, greedy: true, }, - "keyword": /\b(?:static|const|enum|loop|use|break|catch|continue|do|else|finally|for|fun|if|in|fn|nil|return|throw|try|while|val|var|type|match|with|of|abstract|class|interface|private|public|override|open)\b/, + "keyword": /\b(?:static|const|enum|loop|use|break|catch|continue|do|else|finally|for|fun|if|in|fn|nil|return|throw|try|while|val|var|type|match|with|of|abstract|class|interface|private|pub|obj|override|open)\b/, "number": /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i, "operator": /[<>]=?|[!=]=?=?|--?|\$|\+\+?|&&?|\|\|?|[?*/~^%]/, "punctuation": /[{}[\];(),.]/,