-
-
Notifications
You must be signed in to change notification settings - Fork 3
Functions
Andrew Johnson edited this page Nov 20, 2024
·
3 revisions
Functions and methods are an important part of programming in LSTS.
Functions are declared with the let
keyword.
let f(x: U64, y: U64): U64 = x + y;
print( f(123, 456) );
Methods are declared with a dot .
before their name.
let .f(self: MyObject, y: U64): U64 = self.x + y;
print( o.f(123) );
Field syntax is just a sugared method call.
a.f
and
a.f()
are exactly equivalent to
$".f"(a)
however
(a.f)()
is different because it is equivalent to
$".f"(a)()
Function Expressions and Lambdas can be created with the fn
keyword.
[1,2,3].map( fn f(x: U64): U64 = if x>10 then x*x else f(x-1) );
[1,2,3].map( fn(x: U64): U64 = x*x );
The LSTS source code and documentation are released under the terms of the attached permissive MIT license. This license is intended only to protect the future development of the project while otherwise allowing people to use the code and IP as they would like. Please, just be nice.