diff --git a/md/learn/classes/anonymous.md b/md/learn/classes/anonymous.md new file mode 100644 index 0000000..44798ab --- /dev/null +++ b/md/learn/classes/anonymous.md @@ -0,0 +1,32 @@ +# Anonymous classes + + +```thp +class Logger +{ + pub fun log(String msg) + { + print(msg) + } +} + +// Using a class instance +setLogger(Logger()) + +// Using an anonymous class +setLogger(class { + pub fun log(String msg) + { + print(msg) + } +}) +``` + +```thp +setLogger(class(Int param1) -> SomeClass(param1), SomeInterface { + pub fun method() + { + // code + } +}) +``` diff --git a/md/learn/classes/interfaces.md b/md/learn/classes/interfaces.md new file mode 100644 index 0000000..1fca19e --- /dev/null +++ b/md/learn/classes/interfaces.md @@ -0,0 +1,25 @@ +# Interfaces + + + +```thp +interface Serializable +{ + // Methods are always public in interfaces + fun serialize($) -> String +} + + + +class Cat -> Serializable, +{ + pub fun Serializable($) -> String + { + // code + } +} + +``` + +No interface inheritance. + diff --git a/md/learn/classes/magic.md b/md/learn/classes/magic.md new file mode 100644 index 0000000..df03c7b --- /dev/null +++ b/md/learn/classes/magic.md @@ -0,0 +1,16 @@ +# Magic methods + +Are always public + +```thp + +class Cat +{ + pub fun __sleep() -> Array[String] + { + // logic + } +} + +``` + diff --git a/md/learn/functions/declaration.md b/md/learn/functions/declaration.md index fb55aa5..4a05774 100644 --- a/md/learn/functions/declaration.md +++ b/md/learn/functions/declaration.md @@ -62,6 +62,22 @@ val first = get_first_item(numbers) ``` +## Named arguments + +```thp +fun html_special_chars( + String input, + Int? flags, + String? encoding, + Bool? double_encoding, +) -> String +{ + // ... +} + +html_special_chars(input, double_encode: false) +``` + diff --git a/md/learn/index.yaml b/md/learn/index.yaml index a84823a..b94addb 100644 --- a/md/learn/index.yaml +++ b/md/learn/index.yaml @@ -60,3 +60,9 @@ children: path: definition - name: Static path: static + - name: Interfaces + path: interfaces + - name: Anonymous classes + path: anonymous + - name: Magic + path: magic diff --git a/static/index.html b/static/index.html index 9060513..a4a8fce 100644 --- a/static/index.html +++ b/static/index.html @@ -16,7 +16,7 @@ -