Beginning of documentation and website for the PRAKDA language

parent 8aeb0b31
*~
/target
**/*.rs.bk
site/
# Table of Contents
1. [The basics](#orgfb820ab)
1. [Declaring a function](#org5b8b7c5)
<a id="orgfb820ab"></a>
# The basics
<a id="org5b8b7c5"></a>
## Declaring a function
For the better or the worse, PRAKDA has a unique syntax which allows to create functions in an expressive way. Here is an example on how to create an equivalent to a variable with an integer `5` as its value:
make var: () -> int <- Int(5);
The `make` keyword allows the creation or definition of a function. Its name, beginning with a character and composed of characters or numbers, follows. The colon (`:`) marks the beginning of the arguments. There can be either no arguments, marked with `()`, or several of them, marked as shown below. The right arrow `->` indicates the return type of the function, whereas the left arrow `<-` indicates the body of the function. It can either be a one-liner with only one instruction, or it can be a block of instructions surrounded by curly brackets. Here's an example with a naive Fibonacci function:
1 $$$
2 Declaration of the function `fib` which takes either a function returning a
3 literal int or a literal int itself as its argument, and returns a literal int
4 $$$
5 make fib: $ declaration of the `fib` function
6 (i: () -> int) $ takes a function returning an int with no
7 $ argument as argument
8 -> int $ returns a literal int
9 <- { $ beginnig of block of instruction
10
11 make a: $ function `a`
12 (i: () -> int) $ taking an function without argument returning
13 $ a literal int as its argument
14 -> int $ returns a literal int
15 <- fib(i - 1); $ its body is a call to fib
16
17 make b: $ same for function `b`
18 (i: () -> int)
19 -> int
20 <- fib(i - 2);
21
22 make res: $ function `res`
23 (a: (int) -> int), $ takes a function taking an `int` as its
24 $ argument, can be a literal or a returned value
25 $ and returns a literal int
26 (b: (int) -> int), $ same
27 (i: () -> int) $ function returning a literal int without
28 $ argument
29 -> int $ returns a literar int
30 <- a(i) + b(i); $ body, calls `a` and `b` with their argument `i`
31
32 <- res(&a, &b, &i); $ returns evaluation of `res`
33
34 }; $ end of block of instruction for `fib`
A function can be called either by just typing its name if it has no arguments, as we can see on the calls on `i` above, or by typing its name then parenthesis with its arguments inside as we can see with the calls of `a`, `b` and `res`. A function can be passed as arguments without being evaluated by adding the symbol `&` before the name of the function, as we can see on the second to last line above.
Since `a`, `b` and `res` were declared inside the declaration of `fib`, this makes these function only available from within `fib` and cannot be called directly by the user.
As you can see above, comments are marked with the symbol `$`, which makes any character following this symbol ignored by the compiler and the interpreter until the next line break. A multi-line comment is delimited by three `$` and cannot nest other multi-line comments (i.e. if a `$$$` happens, it either begins or ends a comment and cannot be a comment by itself).
Literal values can be given as-is, however their type will be inferred by the compiler and it might not infer the type the user wished for, hence it is recommended to use the built-in functions related to these types, such as `Int(i: () -> int) -> int;` which ensures that `i` is an `int`. By default, an `int` is an signed integer on eight (8) bytes, similar to Rust’s `i64`.
Identifiers live through their scope, which is either the file if they are declared at its root, or the function in which they are declared, such as function arguments or functions declared within other functions. If an identifier is declared in a function which already provides said identifier, the latter is shadowed by the declaration of the former for the rest of its scope. Hence in the functions `a`, `b`, and `res` in the example above, the identifier `i` declared as their argument will be different from `i` declared as an argument of the function `fib`. However since `i` of `a`, `b`, and `res` was declared as an argument for each, it will not overwrite the initial argument of `fib` and will only live in the function in which it was declared. An identifier can be overwritten with the operator `=` followed by a function declaration without a name given after the `make` keyword. Example:
make a: (i: () -> int) -> int <- {
i = make: () -> int <- Int(5); $ `i` gets overwritten by `Int(5)`
<- i;
}
* The basics
** Declaring a function
For the better or the worse, PRAKDA has a unique syntax which allows to create functions in an expressive way. Here is an example on how to create an equivalent to a variable with an integer ~5~ as its value:
#+BEGIN_SRC text
make var: () -> int <- Int(5);
#+END_SRC
The ~make~ keyword allows the creation or definition of a function. Its name, beginning with a character and composed of characters or numbers, follows. The colon (~:~) marks the beginning of the arguments. There can be either no arguments, marked with ~()~, or several of them, marked as shown below. The right arrow ~->~ indicates the return type of the function, whereas the left arrow ~<-~ indicates the body of the function. It can either be a one-liner with only one instruction, or it can be a block of instructions surrounded by curly brackets. Here's an example with a naive Fibonacci function:
#+BEGIN_SRC text -n
$$$
Declaration of the function `fib` which takes either a function returning a
literal int or a literal int itself as its argument, and returns a literal int
$$$
make fib: $ declaration of the `fib` function
(i: () -> int) $ takes a function returning an int with no
$ argument as argument
-> int $ returns a literal int
<- { $ beginnig of block of instruction
make a: $ function `a`
(i: () -> int) $ taking an function without argument returning
$ a literal int as its argument
-> int $ returns a literal int
<- fib(i - 1); $ its body is a call to fib
make b: $ same for function `b`
(i: () -> int)
-> int
<- fib(i - 2);
make res: $ function `res`
(a: (int) -> int), $ takes a function taking an `int` as its
$ argument, can be a literal or a returned value
$ and returns a literal int
(b: (int) -> int), $ same
(i: () -> int) $ function returning a literal int without
$ argument
-> int $ returns a literar int
<- a(i) + b(i); $ body, calls `a` and `b` with their argument `i`
<- res(&a, &b, &i); $ returns evaluation of `res`
}; $ end of block of instruction for `fib`
#+END_SRC
A function can be called either by just typing its name if it has no arguments, as we can see on the calls on ~i~ above, or by typing its name then parenthesis with its arguments inside as we can see with the calls of ~a~, ~b~ and ~res~. A function can be passed as arguments without being evaluated by adding the symbol ~&~ before the name of the function, as we can see on the second to last line above.
Since ~a~, ~b~ and ~res~ were declared inside the declaration of ~fib~, this makes these function only available from within ~fib~ and cannot be called directly by the user.
As you can see above, comments are marked with the symbol ~$~, which makes any character following this symbol ignored by the compiler and the interpreter until the next line break. A multi-line comment is delimited by three ~$~ and cannot nest other multi-line comments (i.e. if a ~$$$~ happens, it either begins or ends a comment and cannot be a comment by itself).
Literal values can be given as-is, however their type will be inferred by the compiler and it might not infer the type the user wished for, hence it is recommended to use the built-in functions related to these types, such as ~Int(i: () -> int) -> int;~ which ensures that ~i~ is an ~int~. By default, an ~int~ is an signed integer on eight (8) bytes, similar to Rust’s ~i64~.
Identifiers live through their scope, which is either the file if they are declared at its root, or the function in which they are declared, such as function arguments or functions declared within other functions. If an identifier is declared in a function which already provides said identifier, the latter is shadowed by the declaration of the former for the rest of its scope. Hence in the functions ~a~, ~b~, and ~res~ in the example above, the identifier ~i~ declared as their argument will be different from ~i~ declared as an argument of the function ~fib~. However since ~i~ of ~a~, ~b~, and ~res~ was declared as an argument for each, it will not overwrite the initial argument of ~fib~ and will only live in the function in which it was declared. An identifier can be overwritten with the operator ~=~ followed by a function declaration without a name given after the ~make~ keyword. Example:
#+BEGIN_SRC text
make a: (i: () -> int) -> int <- {
i = make: () -> int <- Int(5); $ `i` gets overwritten by `Int(5)`
<- i;
}
#+END_SRC
# Table of Contents
1. [PRAKDA, introduction](#orga23b74e)
<a id="orga23b74e"></a>
# PRAKDA, introduction
PRAKDA is a programming language developped and implemented by Phuntsok Drak-pa, aka Phundrak, as a third year university project. It is based on the paradigm “everything is a function”, which implies no distinction between variables and functions.
Below you can see my face when I’m working on this language. You can understand there’s nothing really serious going on with this language.
<div style="text-align:center"><img src ="https://gitlab.phundrak.fr/uploads/-/system/appearance/logo/1/DkazkHiW4AAwvzn.jpg" /></div>1
* PRAKDA, introduction
PRAKDA is a programming language developped and implemented by Phuntsok Drak-pa, aka Phundrak, as a third year university project. It is based on the paradigm “everything is a function”, which implies no distinction between variables and functions.
Below you can see my face when I’m working on this language. You can understand there’s nothing really serious going on with this language.
#+HTML: <div style="text-align:center"><img src ="https://gitlab.phundrak.fr/uploads/-/system/appearance/logo/1/DkazkHiW4AAwvzn.jpg" /></div>1
# Table of Contents
1. [Types](#orgfce2f51)
1. [Types available](#org769fed1)
2. [Types to come](#orga175622)
3. [Changes to come](#org1379873)
<a id="orgfce2f51"></a>
# Types
<a id="org769fed1"></a>
## Types available
- **int:** signed integer coded on four (4) bytes, similar to Rust’s `i32`. Default integer, can be obtained with the built-in function `Int(i: () -> int) -> int;`
<a id="orga175622"></a>
## Types to come
- **float:** signed float coded on four (4) bytes, similar to Rust’s `f32`. Default floating point number, can be obtained with the built-in function `Float(i: () -> float) -> float;`
- **char:** signed character coded on one (1) byte, similar to Rust’s `i8`. Default character type, can be obtained with the built-in function `Char(i: () -> char) -> char;`
- **uint:** unsigned integer coded on four (4) bytes, similar to Rust’s `u32`. Default floating point number, can be obtained with the built-in function `Uint(i: () -> uint) -> uint;`
- **uchar:** unsigned character coded on one (1) byte, similar to Rust’s `u8`. Default floating point number, can be obtained with the built-in function `Uint(i: () -> uint) -> uint;`
<a id="org1379873"></a>
## Changes to come
None for the moment
* Types
** Types available
- int :: signed integer coded on four (4) bytes, similar to Rust’s ~i32~. Default integer, can be obtained with the built-in function ~Int(i: () -> int) -> int;~
** Types to come
- float :: signed float coded on four (4) bytes, similar to Rust’s ~f32~. Default floating point number, can be obtained with the built-in function ~Float(i: () -> float) -> float;~
- char :: signed character coded on one (1) byte, similar to Rust’s ~i8~. Default character type, can be obtained with the built-in function ~Char(i: () -> char) -> char;~
- uint :: unsigned integer coded on four (4) bytes, similar to Rust’s ~u32~. Default floating point number, can be obtained with the built-in function ~Uint(i: () -> uint) -> uint;~
- uchar :: unsigned character coded on one (1) byte, similar to Rust’s ~u8~. Default floating point number, can be obtained with the built-in function ~Uint(i: () -> uint) -> uint;~
** Changes to come
None for the moment
site_name: MKLorum
nav:
- Home: 'index.md'
- Basics: 'basics.md'
- Types: 'types.md'
theme: material
site_url: https://gitlab.phundrak.fr/phundrak/prakda
repo_url: https://gitlab.phundrak.fr/phundrak/prakda
repo_name: 'Gitlab'
site_description: 'Documentation for the PRAKDA programming language'
site_author: 'Lucien Cartier-Tilet'
copyright: 'GPL-3.0'
lang: en
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment