Carp/README.md

47 lines
1.7 KiB
Markdown
Raw Normal View History

2016-01-11 16:52:26 +03:00
# Carp
2016-01-11 16:55:03 +03:00
2016-01-11 17:49:04 +03:00
<img src="https://github.com/eriksvedang/Carp/blob/master/img/temp_logo2.jpg" alt="Logo" align="right" />
2016-01-11 17:46:14 +03:00
2016-01-11 17:57:24 +03:00
Carp is a small programming language designed to work well for interactive and performance sensitive use cases like games, sound synthesis and visualizations.
2016-01-11 17:46:14 +03:00
The key features of Carp are the following:
2016-01-11 18:36:31 +03:00
* Automatic and deterministic memory management (no GC)
* Statically inferred types
2016-01-11 18:47:36 +03:00
* Live reloading of code, REPL-driven development
2016-01-11 18:47:04 +03:00
* Ownership tracking enables a functional programming style while still using mutation for fast updating of data structures
2016-01-11 18:54:33 +03:00
* No hidden performance penalties allocation and copying is explicit
2016-01-11 18:36:31 +03:00
* Very good integration with exisiting C code
2016-01-11 17:57:24 +03:00
## The Language
2016-01-11 18:36:31 +03:00
Carp borrows its looks from Clojure but the runtime semantics are much closer to those of ML or Rust. Here's a sample program:
2016-01-11 17:57:24 +03:00
```clojure
2016-01-11 18:36:31 +03:00
(defn fib (n)
(if (< n 2)
1
(+ (fib (- n 2)) (fib (- n 1)))))
2016-01-11 17:57:24 +03:00
```
2016-01-11 18:50:35 +03:00
This compiles to the equivalent of the following C program:
```C
int fib(int n) {
if(n < 2) {
return 1;
} else {
return fib(n - 2) + fib(n - 1);
}
}
```
2016-01-11 17:57:24 +03:00
## The Compiler
2016-01-11 18:51:46 +03:00
Carp is very tightly integrated with it's compiler which itself is written in a dynamic version of Carp (the dynamic version is implemented in C). To work on a Carp program you run ```carp``` which puts you in the compiler REPL. Everything you want to do with your program can be controlled from here.
2016-01-11 17:57:24 +03:00
2016-01-11 18:36:31 +03:00
For example, to compile the function defined above you would enter the following:
2016-01-11 18:51:46 +03:00
```clojure
λ> (bake fib)
2016-01-11 18:36:31 +03:00
```
2016-01-11 18:54:33 +03:00
This results in the compiler analyzing the code form for 'fib' and compiling it to some very fast binary code, loading this back into the REPL so that it can be called conveniently from there.
2016-01-11 18:36:31 +03:00
2016-01-11 17:57:24 +03:00
(C) Erik Svedäng 2015 - 2016