From 5e712a31418336fb9a4751aeb4a6482c1256cdd1 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 30 Aug 2022 05:54:59 +0000 Subject: [PATCH] Update 'Functions and Methods' --- Functions-and-Methods.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Functions-and-Methods.md diff --git a/Functions-and-Methods.md b/Functions-and-Methods.md new file mode 100644 index 0000000..fa12a90 --- /dev/null +++ b/Functions-and-Methods.md @@ -0,0 +1,33 @@ +# Syntax +``` +func ro someFunction + @ reciever:SomeObject + > input:Int + < output:Int:mut + --- + somePhrase +``` + +Function sections are divided in two. The first part can contain inputs, outputs, and a method reciever. Inputs are preceded by a '>', outputs are preceded by a '<', and the method reciever is preceded by a '@'. Function outputs can have default values, whether they be simple or complex. + +The latter part contains the actual code of the function, which is composed of [phrases](Phrases). + +# Semantics +A function may have any number of inputs and outputs, and they act as local variables. Function inputs +must always be immutable, and function outputs must always be mutable. + +The second part is the actual code of the function. It is separated from the +first part of the function with a separator token, and contains an indented +block of phrases. + +To return data from a function, its outputs must be set as you would a normal +variable. + +A function can be a method of an object if it lists the method receiver. If it doesn't, it is just a regular function + +Method receivers, like inputs, must be immutable. They also must be pointers. +It is important to note that if a pointer is immutable, the pointer cannot +"move", but the data it points to can still be altered. + +Method receivers can be of any type defined in the same module except interface +types. \ No newline at end of file