From 09f0bfcde1b90c1219fcbe2c8ac7225c7ef94400 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Wed, 24 Aug 2022 16:35:09 +0000 Subject: [PATCH] Update 'Functions and Methods' --- Functions-and-Methods.md | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/Functions-and-Methods.md b/Functions-and-Methods.md index f4a7cf2..fa12a90 100644 --- a/Functions-and-Methods.md +++ b/Functions-and-Methods.md @@ -1,15 +1,19 @@ -Functions are written like this: - +# Syntax ``` func ro someFunction + @ reciever:SomeObject > input:Int - < output:Int:mut + < output:Int:mut --- somePhrase ``` -The first part of the function's content is its inputs and outputs. A function -may have any number of these, and they act as local variables. Function inputs +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 @@ -19,16 +23,7 @@ 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 after -an @ symbol: - -``` -func ro setGreeting - @ greeter:{Greeter} - > greeting - --- - set greeter.greeting greeting -``` +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