The Carth Programming Language

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

1 Why Carth?

2 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)
    (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))
  (fun _
    (if (> first last)
      (IterCons first (range (succ first) last)))))

;;? An iterator. Equivalent to a lazy linked list
(type (Iter a)
  (IterCons a (Iter a)))

(define: (succ n)
    (Fun Int Int)
  (+ n 1))

3 Documentation

4 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.

5 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.