Added first draft for the PRAKDA language

parent 15e6e8df
* 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.
* 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);
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 the keywords ~begin~ and ~end~. Here's an example with a naive Fibonacci function:
#+BEGIN_SRC text -n
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
<- begin $ 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; $ 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.
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