Added text to explain support for multiple returns in functions
Also fixed a line with more spaces than needed in parser.lua.
@@ -121,18 +121,16 @@ In Lua 5.4, the default value for this constant is 40 characters.
Function types in Pallene are created with the `->` type constructor.
For example, `(a, b) -> (c)` is the function type for a function that receives two arguments (the first of type `a` and the second of type `b`) and returns a single value of type `c`.
-Then the function receives a single input parameter, or returns a single value, the parenthesis can be omitted from the function type.
+If the function receives a single input parameter, or returns a single value, the parenthesis can be omitted from the function type.
The following are more examples of valid function types:
```
int -> float
(int, int) -> float
+(int, int) -> (float, float)
string -> ()
```
-The current Pallene implementation only supports functions with 0 or 1 return values.
-We plan to support functions with two or more return values in a future version.
-
The arrow type constructor is right-associative.
That is, `a -> b -> c` means `a -> (b -> c)`.
@@ -242,24 +240,28 @@ end
Module-local variables are declared with the following syntax:
```
-local <name> [: type] = <exp>
+local <name> [: type] {, <name> [: type]} = <exp> {, <exp>}
```
+It is possible to declare multiple variables at once.
+
+The behaviour for expressions that are function calls is the same as in Lua.
+
### Functions
Functions are declared as follows:
```
-[local] function <name>([<params>])[: <rettypes>]
+[local] function <name>([<params>])[: [(]<rettypes>[)]]
<body>
end
```
A `local` function is only visible inside the module it is defined.
-Non-local functions exported, which means that they are accessible to Lua if it requires the Pallene module.
+Non-local functions are exported, which means that they are accessible to Lua if it requires the Pallene module.
As with variables, `<name>` can be any valid identifier, but it is a compile-time error to declare two functions with the same name, or a function with the same name as a module variable.
-The return types `<rettypes>` are optional, and if not given it is assumed that the function does not return anything.
+The return types `<rettypes>` are optional, and if not given it is assumed that the function does not return anything. If two or more return types are present, a parenthesis surrounding `<rettypes>` is obligatory.
Parameters are a comma-separated list of `<name>: <type>`.
Two parameters cannot have the same name.
@@ -367,14 +369,16 @@ As usual, {A} means 0 or more As, and \[A\] means an optional A.
toplevelrecord ::= record Name {recordfield} end
recordfield ::= NAME ':' type [';']
- toplevelvar ::= local NAME [':' type] '=' exp
+ toplevelvar ::= local NAME [':' type] {',' NAME [':' type]} '=' explist
- toplevelfunc ::= [local] function NAME '(' [paramlists] ')' [':' type] block end
+ toplevelfunc ::= [local] function NAME '(' [paramlists] ')' [':' ['('] typelist [')']] block end
paramlist ::= NAME ':' type {',' NAME ':' type}
type ::= nil | integer | float | boolean | string | any | '{' type '}' | NAME
+ typelist ::= type {',' type}
+
block ::= {statement} [returnstat]
statement ::= ';' |
@@ -394,6 +398,8 @@ As usual, {A} means 0 or more As, and \[A\] means an optional A.
exp ::= nil | false | true | NUMBER | STRING | initlist | exp as type |
unop exp | exp binop exp | funccall | '(' exp ')' | exp '.' NAME
+ explist ::= exp {',' exp}
+
funccall ::= exp funcargs
funcargs ::= '(' [explist] ')' | initlist | STRING
