From 48d3d26a4aba521dc3cbe515f0c6b31f707b79c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Przemys=C5=82aw=20Pluta?= Date: Mon, 23 Mar 2020 20:54:47 +0100 Subject: [PATCH] Created smnp.lang (markdown) --- smnp.lang.md | 157 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 smnp.lang.md diff --git a/smnp.lang.md b/smnp.lang.md new file mode 100644 index 0000000..264241c --- /dev/null +++ b/smnp.lang.md @@ -0,0 +1,157 @@ +The `smnp.lang` module provides essential functions and methods that haven't been implemented directly in SMNP interpreter. The `smnp.lang` is kind of privileged because of fact, that it is implicitly loaded in _each_ SMNP script, even without any `import` statement. + +# 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: )` +Creates new `int` from other `int` or `float`. +The construction is typically used in other stdlib modules to round `float` types down. + +### Arguments +* value of `int` or `float` type + +### Output +* newly created `int` + +### Example +``` +x = 3.14; +y = Int(x); + +println(typeOf(y)); # int +println(y); # 3 +``` + +## `Note(pitch: string, octave: int, duration: int, dot: bool)` +Creates new `note` with given parameters. + +### 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 + +### Output +* note of given parameters + +### Example +``` +x = Note("Eb", 3, 16, true); +println(x == @Eb3:16d); # true +``` + +## `Note(pitch: string, octave: int, durationNumerator: int, durationDenominator: int)` +Creates new `note` with given parameters. + +### 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: +``` +When: +durationNumerator == durationDenominator -> whole note +durationNumerator == 0.5 * durationDenominator -> half note +durationNumerator == 0.25 * durationDenominator -> quarter note +... +``` +* `durationDenominator` - as above + +### Output +* note of given parameters + +### Example +``` +x = Note("Eb", 3, 3, 32); +println(x == @Eb3:16d); # true +``` + +# Functions +## `typeOf(object)` +Returns the type name of passed object. + +### Arguments +* object - object of any type + +### Output +* type name of passed object as string + +### Example +``` +println(typeOf(14)); # integer +println(typeOf(@A#)); # note +println(typeOf([1, 2, 3])); # list +println(typeOf([@c, @d, 4])); # list +println(typeOf({ c -> @c, d -> @d })); # map +``` + +# Methods +## `.get(index: int)` +Returns list element of given index. + +### Arguments +* index - index of desired element. Note, that counting starts with 0. + +### Output +* element of list with given index. Throws an error if index is out of bounds. + +### Example +``` +myList = [1, 2, 3, 4]; +lastElement = myList.get(3); +println(lastElement); # 4 +``` + +## `.get(key: )` +Returns map element associated with given key. + +### Arguments +* key - key of value that is about to be returned + +### Output +* element associated with given key. Throws an error if key doesn't exist. + +### Example +``` +myMap = { + true -> false, + @Eb3:2d -> 14, + hello -> "world" +}; + +element = myMap.get("hello"); +println(element); # world +``` + +## `.charAt(index: int)` +Returns string's character of given index. + +### Arguments +* index - index of desired character. Counting starts with 0. + +### Output +*character of given index. Throws an error if index is out of bounds. + +### Example +``` +x = "hello"; +println(x.charAt(1)); # e +``` + +## `.toString()` +Returns a string representation of any available object. + +### Arguments +_none_ + +### Output +* string representation of object + +### Example +``` +println(@Eb3:8d.toString()); # D#3:(3/16) + +println(typeOf(14.toString())); # string +println(typeOf("hello, world".toString())); # string +println(typeOf(true.toString())); # string +println(typeOf(@Gb3:16d.toString())); # string +println(typeOf({ first -> @c, second -> [1, 2, 3] }.toString())); # string +``` \ No newline at end of file