# The Carth Programming Language

Purely functional programming with lisp-syntax. Less infix, more parens!

## 1WORK IN PROGRESS

Just as a little disclaimer: this project is in the very early stages of development, so there are no guarantees of stability etc.

## 3 Example

Just to give you a quick taste. More examples can be found in the `examples` directory in the repository.

```;; Disclaimer: This doesn't quite work yet, but we're getting close!

(define main fizzbuzz)

(define (fizzbuzz _)
(foldr (after seq (after display fizzbuzz'))
unit
(range 0 100)))

(define (fizzbuzz' n)
(match (Pair (% n 3) (% n 5))
[(Pair 0 0) "Fizzbuzz"]
[(Pair 0 _) "Fizz"]
[(Pair _ 0) "Buzz"]
[_ (show-int n)]))

(type (Pair a b)
(Pair a b))

;; We implement some routines in a helper library in a language with C FFI, like
;; Rust.
(extern display (Fun String Unit))
(extern show-int (Fun Int String))

;;? Function composition. Read "f after g".
(define: (after f g x)
(forall [a b c] (Fun (Fun b c) (Fun a b) (Fun a c)))
(f (g x)))

;;? Sequence operations
(define (seq _ b) b)

;;? Inclusive range
(define: (range first last)
(Fun Int Int (Iter Int))
(Iter (fun _
(if (> first last)
None
(Some (Pair first (range (succ first) last)))))))

;;? An iterator. Equivalent to a lazy linked list
(type (Iter a)
(Iter (Fun Unit (Maybe (Pair a (Iter a))))))

(type (Maybe a)
None
(Some a))

(define: (foldr f b as)
(forall [a b] (Fun (Fun a b b) b (Iter a) b))
(match (next as)
[None b]
[(Some a as') (f a (foldr f b as'))]))

(define: next
(forall [a] (Fun (Iter a) (Maybe (Pair a (Iter a)))))
(fun-match
[(Iter f) (f unit)]))

(define (succ n) (+ n 1))
```

## 5 Development

All development on the Carth project happens openly on GitLab in `JoJoZ/carth`. The source for this website is also on GitLab in `JoJoZ/carth-website`.