The Carth Programming Language

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


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

2 Why Carth?

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'))
         (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)
            (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)
  (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)))))
    [(Iter f) (f unit)]))

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

4 Documentation

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.

6 License

Both the Carth project and this website itself are licensed under the AGPLv3.

Copyright (C) 2019 Johan Johansson

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.