Updated smnp.lang (markdown)
58
smnp.lang.md
58
smnp.lang.md
@@ -2,11 +2,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(value: <int, float>)`
|
## Int
|
||||||
|
```
|
||||||
|
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
|
||||||
```
|
```
|
||||||
x = 3.14;
|
x = 3.14;
|
||||||
y = Int(x);
|
y = Int(x);
|
||||||
@@ -15,25 +18,31 @@ println(typeOf(y)); # int
|
|||||||
println(y); # 3
|
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.
|
Creates new `note` with given parameters.
|
||||||
|
|
||||||
### Arguments
|
#### Arguments
|
||||||
* `pitch` - the pitch of note. Available values: `C, Cb, C#, D, Db, D#, E, ...`
|
* `pitch` - the pitch of note. Available values: `C, Cb, C#, D, Db, D#, E, ...`
|
||||||
* `octave` - the octave of note
|
* `octave` - the octave of note
|
||||||
* `duration` - the denominator of fraction that determines the duration of note: `1 = whole, 2 = half, 4 = quarter, ...`
|
* `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
|
* `dot` - an optional dot which extends the note duration by half of its value
|
||||||
|
|
||||||
### Example
|
#### Example
|
||||||
```
|
```
|
||||||
x = Note("Eb", 3, 16, true);
|
x = Note("Eb", 3, 16, true);
|
||||||
println(x == @Eb3:16d); # 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.
|
Creates new `note` with given parameters.
|
||||||
|
|
||||||
### Arguments
|
#### Arguments
|
||||||
* `pitch` - the pitch of note. Available values: `C, Cb, C#, D, Db, D#, E, ...`
|
* `pitch` - the pitch of note. Available values: `C, Cb, C#, D, Db, D#, E, ...`
|
||||||
* `octave` - the octave of note
|
* `octave` - the octave of note
|
||||||
* `durationNumerator` - together with `durationDenominator` determines the total duration 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
|
* `durationDenominator` - as above
|
||||||
|
|
||||||
### Example
|
#### Example
|
||||||
```
|
```
|
||||||
x = Note("Eb", 3, 3, 32);
|
x = Note("Eb", 3, 3, 32);
|
||||||
println(x == @Eb3:16d); # true
|
println(x == @Eb3:16d); # true
|
||||||
```
|
```
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
## `typeOf(object)`
|
## typeOf
|
||||||
|
```
|
||||||
|
typeOf(object)
|
||||||
|
```
|
||||||
Returns the type name of passed object.
|
Returns the type name of passed object.
|
||||||
|
|
||||||
### Example
|
#### Example
|
||||||
```
|
```
|
||||||
println(typeOf(14)); # integer
|
println(typeOf(14)); # integer
|
||||||
println(typeOf(@A#)); # note
|
println(typeOf(@A#)); # note
|
||||||
@@ -66,20 +78,26 @@ println(typeOf({ c -> @c, d -> @d })); # map
|
|||||||
```
|
```
|
||||||
|
|
||||||
# Methods
|
# 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`.
|
Returns list element of given index or throws error if index is greater than `list.size - 1`.
|
||||||
|
|
||||||
### Example
|
#### Example
|
||||||
```
|
```
|
||||||
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(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.
|
Returns map element associated with given key or throws an error if key doesn't exist in the map.
|
||||||
|
|
||||||
### Example
|
#### Example
|
||||||
```
|
```
|
||||||
myMap = {
|
myMap = {
|
||||||
true -> false,
|
true -> false,
|
||||||
@@ -91,14 +109,20 @@ element = myMap.get("hello");
|
|||||||
println(element); # world
|
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`.
|
Returns string's character of given index or throws error if index is greater than `string.length - 1`.
|
||||||
|
|
||||||
### Example
|
#### Example
|
||||||
```
|
```
|
||||||
x = "hello";
|
x = "hello";
|
||||||
println(x.charAt(1)); # e
|
println(x.charAt(1)); # e
|
||||||
```
|
```
|
||||||
|
|
||||||
## `<any>.toString()`
|
## <any>.toString
|
||||||
|
```
|
||||||
|
<any>.toString()
|
||||||
|
```
|
||||||
Returns a string representation of object.
|
Returns a string representation of object.
|
||||||
|
|||||||
Reference in New Issue
Block a user