Updated smnp.lang (markdown)
30
smnp.lang.md
30
smnp.lang.md
@@ -3,14 +3,14 @@ The `smnp.lang` module provides essential functions and methods that haven't bee
|
|||||||
# Constructors
|
# Constructors
|
||||||
Constructors technically are nothing but functions. They just "emulate" real constructors from other general purpose programming languages that support object-oriented programming paradigm.
|
Constructors technically are nothing but functions. They just "emulate" real constructors from other general purpose programming languages that support object-oriented programming paradigm.
|
||||||
## Int
|
## Int
|
||||||
```
|
```php
|
||||||
Int(value: <int, float>)
|
Int(value: <int, float>)
|
||||||
```
|
```
|
||||||
Creates new `int` from other `int` or `float`.
|
Creates new `int` from other `int` or `float`.
|
||||||
The construction is typically used in other stdlib modules to round `float` types down.
|
The construction is typically used in other stdlib modules to round `float` types down.
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
```
|
```php
|
||||||
x = 3.14;
|
x = 3.14;
|
||||||
y = Int(x);
|
y = Int(x);
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ println(y); # 3
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Note
|
## Note
|
||||||
```
|
```php
|
||||||
Note(pitch: string, octave: int, duration: int, dot: bool) #1
|
Note(pitch: string, octave: int, duration: int, dot: bool) #1
|
||||||
Note(pitch: string, octave: int, durNumerator: int, durDenominator: int) #2
|
Note(pitch: string, octave: int, durNumerator: int, durDenominator: int) #2
|
||||||
```
|
```
|
||||||
@@ -44,7 +44,7 @@ durNumerator == 0.25 * durDenominator -> quarter note
|
|||||||
* `durDenominator` - as above
|
* `durDenominator` - as above
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
```
|
```php
|
||||||
x = Note("Eb", 3, 16, true);
|
x = Note("Eb", 3, 16, true);
|
||||||
y = Note("Eb", 3, 3, 32);
|
y = Note("Eb", 3, 3, 32);
|
||||||
println(x == @Eb3:16d); # true
|
println(x == @Eb3:16d); # true
|
||||||
@@ -53,13 +53,13 @@ println(y == @Eb3:16d); # true
|
|||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
## typeOf
|
## typeOf
|
||||||
|
```php
|
||||||
|
typeOf(item)
|
||||||
```
|
```
|
||||||
typeOf(object)
|
Returns the type name of passed item.
|
||||||
```
|
|
||||||
Returns the type name of passed object.
|
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
```
|
```php
|
||||||
println(typeOf(14)); # integer
|
println(typeOf(14)); # integer
|
||||||
println(typeOf(@A#)); # note
|
println(typeOf(@A#)); # note
|
||||||
println(typeOf([1, 2, 3])); # list
|
println(typeOf([1, 2, 3])); # list
|
||||||
@@ -69,26 +69,26 @@ println(typeOf({ c -> @c, d -> @d })); # map
|
|||||||
|
|
||||||
# Methods
|
# Methods
|
||||||
## list.get
|
## list.get
|
||||||
```
|
```php
|
||||||
list.get(index: int)
|
list.get(index: int)
|
||||||
```
|
```
|
||||||
Returns list element of given index or throws error if index is greater than `list.size - 1`.
|
Returns list element of given index or throws error if index is greater than `list.size - 1`.
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
```
|
```php
|
||||||
myList = [1, 2, 3, 4];
|
myList = [1, 2, 3, 4];
|
||||||
lastElement = myList.get(3);
|
lastElement = myList.get(3);
|
||||||
println(lastElement); # 4
|
println(lastElement); # 4
|
||||||
```
|
```
|
||||||
|
|
||||||
## map.get
|
## map.get
|
||||||
```
|
```php
|
||||||
map.get(key: <int, note, string, bool>)
|
map.get(key: <int, note, string, bool>)
|
||||||
```
|
```
|
||||||
Returns map element associated with given key or throws an error if key doesn't exist in the map.
|
Returns map element associated with given key or throws an error if key doesn't exist in the map.
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
```
|
```php
|
||||||
myMap = {
|
myMap = {
|
||||||
true -> false,
|
true -> false,
|
||||||
@Eb3:2d -> 14,
|
@Eb3:2d -> 14,
|
||||||
@@ -100,19 +100,19 @@ println(element); # world
|
|||||||
```
|
```
|
||||||
|
|
||||||
## string.charAt
|
## string.charAt
|
||||||
```
|
```php
|
||||||
string.charAt(index: int)
|
string.charAt(index: int)
|
||||||
```
|
```
|
||||||
Returns string's character of given index or throws error if index is greater than `string.length - 1`.
|
Returns string's character of given index or throws error if index is greater than `string.length - 1`.
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
```
|
```php
|
||||||
x = "hello";
|
x = "hello";
|
||||||
println(x.charAt(1)); # e
|
println(x.charAt(1)); # e
|
||||||
```
|
```
|
||||||
|
|
||||||
## \<any\>.toString
|
## \<any\>.toString
|
||||||
```
|
```php
|
||||||
<any>.toString()
|
<any>.toString()
|
||||||
```
|
```
|
||||||
Returns a string representation of object.
|
Returns a string representation of object.
|
||||||
Reference in New Issue
Block a user