Updated smnp.lang (markdown)

Bartłomiej Przemysław Pluta
2020-03-27 17:56:42 +01:00
parent b0f8047ad0
commit b24a5a9391

@@ -2,11 +2,14 @@ The `smnp.lang` module provides essential functions and methods that haven't bee
# Constructors
Constructors technically are nothing but functions. They just "emulate" real constructors from other general purpose programming languages that support object-oriented programming paradigm.
## `Int(value: <int, float>)`
## Int
```
Int(value: <int, float>)
```
Creates new `int` from other `int` or `float`.
The construction is typically used in other stdlib modules to round `float` types down.
### Example
#### Example
```
x = 3.14;
y = Int(x);
@@ -15,25 +18,31 @@ println(typeOf(y)); # int
println(y); # 3
```
## `Note(pitch: string, octave: int, duration: int, dot: bool)`
## Note
```
Note(pitch: string, octave: int, duration: int, dot: bool)
```
Creates new `note` with given parameters.
### Arguments
#### Arguments
* `pitch` - the pitch of note. Available values: `C, Cb, C#, D, Db, D#, E, ...`
* `octave` - the octave of note
* `duration` - the denominator of fraction that determines the duration of note: `1 = whole, 2 = half, 4 = quarter, ...`
* `dot` - an optional dot which extends the note duration by half of its value
### Example
#### Example
```
x = Note("Eb", 3, 16, true);
println(x == @Eb3:16d); # true
```
## `Note(pitch: string, octave: int, durationNumerator: int, durationDenominator: int)`
## Note
```
Note(pitch: string, octave: int, durationNumerator: int, durationDenominator: int)
```
Creates new `note` with given parameters.
### Arguments
#### Arguments
* `pitch` - the pitch of note. Available values: `C, Cb, C#, D, Db, D#, E, ...`
* `octave` - the octave of note
* `durationNumerator` - together with `durationDenominator` determines the total duration of note:
@@ -46,17 +55,20 @@ durationNumerator == 0.25 * durationDenominator -> quarter note
```
* `durationDenominator` - as above
### Example
#### Example
```
x = Note("Eb", 3, 3, 32);
println(x == @Eb3:16d); # true
```
# Functions
## `typeOf(object)`
## typeOf
```
typeOf(object)
```
Returns the type name of passed object.
### Example
#### Example
```
println(typeOf(14)); # integer
println(typeOf(@A#)); # note
@@ -66,20 +78,26 @@ println(typeOf({ c -> @c, d -> @d })); # map
```
# Methods
## `list.get(index: int)`
## list.get
```
list.get(index: int)
```
Returns list element of given index or throws error if index is greater than `list.size - 1`.
### Example
#### Example
```
myList = [1, 2, 3, 4];
lastElement = myList.get(3);
println(lastElement); # 4
```
## `map.get(key: <int, note, string, bool>)`
## map.get
```
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.
### Example
#### Example
```
myMap = {
true -> false,
@@ -91,14 +109,20 @@ element = myMap.get("hello");
println(element); # world
```
## `string.charAt(index: int)`
## string.charAt
```
string.charAt(index: int)
```
Returns string's character of given index or throws error if index is greater than `string.length - 1`.
### Example
#### Example
```
x = "hello";
println(x.charAt(1)); # e
```
## `<any>.toString()`
## <any>.toString
```
<any>.toString()
```
Returns a string representation of object.