Skip to content
Proyek

Tentang

Coalton adalah bahasa pemrograman fungsional yang efisien dan bertipe statis, yang meningkatkan kemampuan Common Lisp.

Bahasa pemrograman dan runtime

Cara angka ini diukur

1,803 bintang113 Fork +1 dalam 24 jam

Pertumbuhan bintang terukur

dalam 24 jam
+1
dalam 7 hari
+5
dalam 15 hari
+10
dalam 1 bulan
+16

Perubahan bersih pada periode yang tumpang tindih, bukan total harian. Pengukuran yang belum tersedia dibiarkan kosong. Bintang menunjukkan perhatian, bukan kualitas.

README.md

Asli

Coalton

Github Workflow Status Discord

Coalton is an efficient, statically typed functional programming language that supercharges Common Lisp.

Coalton integrates directly into Common Lisp:

(defpackage #:differentiation
  (:use #:coalton #:coalton-prelude)
  (:local-nicknames (#:sym #:coalton/symbol))
  (:export #:Expr #:EConst #:EVar #:E+ #:E*)
  (:export #:diff #:t #:d/dt))

(in-package #:differentiation)

(named-readtables:in-readtable coalton:coalton)

(coalton-toplevel
  ;; Define a new parametric algebraic data type for simple
  ;; mathematical expressions.
  (define-type (Expr :t)
    "A symbolic expression of basic arithmetic."
    (EConst :t)
    (EVar   sym:Symbol)
    (E+     (Expr :t) (Expr :t))
    (E*     (Expr :t) (Expr :t)))

  ;; The classic `diff` function, in Coalton.
  (declare diff (Num :t => sym:Symbol * Expr :t -> Expr :t))
  (define (diff x f)
    "Compute the derivative of `f` with respect to `x`."
    (match f
      ((EConst _)                       ; c' = 0
       (EConst 0))
      ((EVar s)                         ; x' = 1
       (if (== s x) (EConst 1) (EConst 0)))
      ((E+ a b)                         ; (a+b)' = a' + b'
       (E+ (diff x a) (diff x b)))
      ((E* a b)                         ; (ab)' = a'b + ab'
       (E+ (E* (diff x a) b)
           (E* a          (diff x b))))))

  ;; We can use `t` just fine since Coalton doesn't import `cl:t`.
  (define t (sym:make-symbol "t"))

  (declare d/dt (Num :t => Expr :t -> Expr :t))
  (define (d/dt f)
    "The time derivative operator."
    (diff t f)))

It also works directly in the REPL:

CL-USER> (in-package #:differentiation)
DIFFERENTIATION> (coalton-toplevel
                   (define (square x) (E* x x)))
;; SQUARE :: ∀ A. ((EXPR A) → (EXPR A))

DIFFERENTIATION> (coalton (d/dt (E+ (square (EVar t)) (EConst 1))))
#.(E+ #.(E+ #.(E* #.(ECONST 1) #.(EVAR |t|))
            #.(E* #.(EVAR |t|) #.(ECONST 1)))
      #.(ECONST 0))

Type errors are discovered at compile-time, and errors are printed beautifully without sacrificing Common Lisp's interactive debugging facilities.

DIFFERENTIATION> (coalton (d/dt (E+ (EConst 1/2) (EConst 0.5))))
error: Type mismatch
  --> repl:1:32
   |
 1 |  (coalton (d/dt (E+ (EConst 1/2) (EConst 0.5))))
   |                                  ^^^^^^^^^^^^ Expected type '(EXPR FRACTION)' but got '(EXPR F32)'

Coalton is used in production to build defense and quantum computing software.

Getting started

[!WARNING] Coalton has not reached "1.0" yet. This means that, from time to time, you may have a substandard user experience. While we try to be ANSI-conforming, Coalton is currently only tested on recent versions of SBCL and Clozure CL.

The version of Coalton that may be in Quicklisp may not be up-to-date.

Install SBCL and Quicklisp. In Windows PowerShell or a macOS/Linux shell, clone Coalton where ASDF can find it:

git clone https://github.com/coalton-lang/coalton.git "$HOME/common-lisp/coalton"
cd "$HOME/common-lisp/coalton"
sbcl --no-userinit --load "$HOME/quicklisp/setup.lisp" --load scripts/fetch-dependencies.lisp

At the SBCL prompt, fetch the dependencies once, then load Coalton. In later sessions, start with asdf:load-system.

(cl-user::fetch-dependencies "coalton/tests") ; only once
(asdf:load-system "coalton")
(in-package :coalton-user)

To run the tests, switch back with (in-package :cl-user), then evaluate (asdf:test-system "coalton"). To use Coalton in your own project, add "coalton" to its :depends-on list.

Learn: Start with Coalton Language Guide, the language manual, and the standard library reference, and then take a peek at the examples directory. It may also be helpful to check out the introductory blog post.

Open Source Community: Awesome Coalton has a list of community-built libraries, applications, and examples, that you can use in your own projects or as examples to learn from.

What's here?

This repository contains the source code to the Coalton compiler, and the standard library. It also contains two optional libraries, which are not loaded by default: coalton/xmath, for extended mathematics, and coalton/threads, for threads, synchronization, and parallel computation (SBCL only).

It also contains a few example programs, such as:

Lastly and importantly, we maintain a collection of documentation about Coalton in the docs directory.

Get involved

Want to ask a question about Coalton, propose a feature, or share a cool program you wrote? Try posting in the GitHub Discussions page!

We welcome contributions of all forms, especially as we stabilize toward a 1.0 release. We would be grateful to receive:

  • bug reports (filed as issues),
  • bug fixes and typo corrections (filed as pull requests),
  • small example programs, and
  • user experience troubles.

Jelajahi proyek terkait

Memuat…