class constants added and class instances for integral types
This commit is contained in:
1 parent
f885300d18
commit
47c061d2b4
7 files changed
+98
-16
No files matched your search
+19
-5
@@ -40,14 +40,28 @@ Class is the object, naturally, with class:
|
||||
|
||||
Classes can be compared:
|
||||
|
||||
println(1.21::class == Math.PI::class)
|
||||
println(3.14::class == 1::class)
|
||||
println(π::class)
|
||||
>>> true
|
||||
>>> false
|
||||
assert(1.21::class == Math.PI::class)
|
||||
assert(3.14::class != 1::class)
|
||||
assert(π::class == Real)
|
||||
π::class
|
||||
>>> Real
|
||||
|
||||
Note `Real` class: it is global variable for Real class; there are such class instances for all built-in types:
|
||||
|
||||
assert("Hello"::class == String)
|
||||
assert(1970::class == Int)
|
||||
assert(true::class == Bool)
|
||||
>>> void
|
||||
|
||||
More complex is singleton classes, because you don't need to compare their class
|
||||
instances and generally don't need them at all, these are normally just Obj:
|
||||
|
||||
null::class
|
||||
>>> Obj
|
||||
|
||||
At this time, `Obj` can't be accessed as a class.
|
||||
|
||||
|
||||
### Methods in-depth
|
||||
|
||||
Regular methods are called on instances as usual `instance.method()`. The method resolution order is
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# Real built-in class
|
||||
|
||||
Class that supports double-precision math. Woks much like double in other languages. We honor no floats, so it is '
|
||||
Real'.
|
||||
|
||||
It's class in Ling is `Real`:
|
||||
|
||||
(π/2)::class
|
||||
>>> Real
|
||||
|
||||
you can use it's class to ensure type:
|
||||
|
||||
1.71::class == Real
|
||||
>>> true
|
||||
|
||||
## Member functions
|
||||
|
||||
| name | meaning | type |
|
||||
|--------------|------------------------------------|------|
|
||||
| `roundToInt` | round to nearest int like round(x) | Int |
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
Reference in new issue
Block a user