Keli Language
https://github.com/KeliLanguage/compiler/
Search…
Motivation
Showcase
Design goals
Features
Specification
Section 1: Introduction
Section 2: Lexical Structure
Section 3: Basic Expressions
Section 4: Magic Expressions
Section 5: Declarations
Section 6: Modules
Section 7: Type annotations
Section 8: Packages
Style guide
Naming conventions
Techniques
Singleton
Default values for functions
Installation
How to install Keli?
Tutorial
Creating a new package
CONTRIBUTE
Github source
Blog
Interval comparison operator for free!
Powered By
GitBook
Singleton
Purpose
Sometimes, when we are creating libraries for other users, we might want to group similar functions together to improve user experience.
Example
Suppose we are creating a library that allow the user to access the file system. And we wish that our code looks like this:
1
=
fs
.
open
(
"Hello world.txt"
)
Copied!
First, we need to create a
tagged union
with only a single tag:
1
FileSystem
=
choice
.
new
Copied!
Then, create a constant alias:
1
fs
=
FileSystem
.
new
Copied!
After that, we can proceed to define the functions we intend to expose:
1
(
this FileSystem
).
open
(
filename String
)
=
undefined
2
(
this FileSystem
).
rename
(
oldname String
)
as
(
newname String
)
=
undefined
3
(
this FileSystem
).
delete
(
filename String
)
=
undefined
Copied!
And the client can use them as follows:
1
=
fs
.
open
(
"Hello world.txt"
)
2
=
fs
.
rename
(
"Jojo.md"
)
as
(
"Koko.md"
)
3
=
fs
.
delete
(
"/"
)
Copied!
Style guide - Previous
Naming conventions
Next - Techniques
Default values for functions
Last modified
3yr ago
Copy link
Contents
Purpose
Example