Changes
This commit is contained in:
parent
540f9c41e5
commit
45bbfa0ebd
@ -31,8 +31,8 @@ class SimpleClass
|
|||||||
// Properties are private by default
|
// Properties are private by default
|
||||||
var String? name;
|
var String? name;
|
||||||
|
|
||||||
// Made public with `public`
|
// Made public with `pub`
|
||||||
public var String? surname;
|
pub var String? surname;
|
||||||
|
|
||||||
// Methods are private by default
|
// Methods are private by default
|
||||||
fun display_name($)
|
fun display_name($)
|
||||||
@ -41,7 +41,7 @@ class SimpleClass
|
|||||||
print($name)
|
print($name)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun get_name($) -> String?
|
pub fun get_name($) -> String?
|
||||||
{
|
{
|
||||||
$name
|
$name
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ Kotlin style
|
|||||||
```thp
|
```thp
|
||||||
class Cat(val String name)
|
class Cat(val String name)
|
||||||
{
|
{
|
||||||
public fun get_name($) -> String
|
pub fun get_name($) -> String
|
||||||
{
|
{
|
||||||
$name
|
$name
|
||||||
}
|
}
|
||||||
@ -78,7 +78,7 @@ Kotlin style
|
|||||||
```thp
|
```thp
|
||||||
class Animal(val String name)
|
class Animal(val String name)
|
||||||
{
|
{
|
||||||
public fun say_name($)
|
pub fun say_name($)
|
||||||
{
|
{
|
||||||
print($name)
|
print($name)
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ interface Serializable
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Cat -> Serializable,
|
class Cat -> Serializable
|
||||||
{
|
{
|
||||||
pub fun Serializable($) -> String
|
pub fun Serializable($) -> String
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Magic methods
|
# Magic methods
|
||||||
|
|
||||||
Are always public
|
Don't get special treatment.
|
||||||
|
|
||||||
```thp
|
```thp
|
||||||
|
|
||||||
@ -14,3 +14,7 @@ class Cat
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
```thp
|
||||||
|
|
||||||
|
```
|
||||||
|
@ -4,7 +4,13 @@
|
|||||||
## Class constants
|
## Class constants
|
||||||
|
|
||||||
```thp
|
```thp
|
||||||
static Cat {
|
class Cat
|
||||||
|
{
|
||||||
|
// Stateful code
|
||||||
|
}
|
||||||
|
|
||||||
|
static Cat
|
||||||
|
{
|
||||||
const CONSTANT = "constant value"
|
const CONSTANT = "constant value"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,8 +24,10 @@ aka. plain, old functions
|
|||||||
|
|
||||||
|
|
||||||
```thp
|
```thp
|
||||||
static Cat {
|
static Cat
|
||||||
fun static_method() -> Int {
|
{
|
||||||
|
fun static_method() -> Int
|
||||||
|
{
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -34,8 +42,9 @@ aka. global variables
|
|||||||
|
|
||||||
|
|
||||||
```thp
|
```thp
|
||||||
static Cat {
|
static Cat
|
||||||
public var access_count = 0
|
{
|
||||||
|
pub var access_count = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
print(Cat::access_count) // 0
|
print(Cat::access_count) // 0
|
||||||
|
@ -58,7 +58,7 @@ while index < colors.size()
|
|||||||
|
|
||||||
## Infinite loop
|
## Infinite loop
|
||||||
|
|
||||||
Basically Rust's loop.
|
Basically Rust*'s loop.
|
||||||
|
|
||||||
```thp
|
```thp
|
||||||
loop
|
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.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,7 +78,20 @@ fun html_special_chars(
|
|||||||
html_special_chars(input, double_encode: false)
|
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: "-")
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,6 +17,9 @@ fun map[A, B](Array[A] input, (A) -> B function) -> Array[B]
|
|||||||
fun generate_generator() -> () -> Int
|
fun generate_generator() -> () -> Int
|
||||||
{
|
{
|
||||||
// code...
|
// code...
|
||||||
|
return fun() {
|
||||||
|
322
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ Prism.languages.thp = {
|
|||||||
pattern: /(["])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
pattern: /(["])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
||||||
greedy: true,
|
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,
|
"number": /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
|
||||||
"operator": /[<>]=?|[!=]=?=?|--?|\$|\+\+?|&&?|\|\|?|[?*/~^%]/,
|
"operator": /[<>]=?|[!=]=?=?|--?|\$|\+\+?|&&?|\|\|?|[?*/~^%]/,
|
||||||
"punctuation": /[{}[\];(),.]/,
|
"punctuation": /[{}[\];(),.]/,
|
||||||
|
Loading…
Reference in New Issue
Block a user