Skip to content

Commit

Permalink
lisp -> coal
Browse files Browse the repository at this point in the history
hash.coal

builtin.coal

math/arith.coal

num.coal

bounded.coal
  • Loading branch information
jbouwman committed Aug 21, 2024
1 parent 9e6b4cf commit d5bd300
Show file tree
Hide file tree
Showing 14 changed files with 1,294 additions and 1,307 deletions.
12 changes: 6 additions & 6 deletions coalton.asd
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@
(:file "utils")
(:coalton-file "types")
(:coalton-file "primitive-types")
(:file "classes")
(:file "hash")
(:file "builtin")
(:coalton-file "classes")
(:coalton-file "hash")
(:coalton-file "builtin")
(:coalton-file "functions")
(:coalton-file "boolean")
(:coalton-file "bits")
(:module "math"
:serial t
:components ((:file "arith")
(:file "num")
(:file "bounded")
:components ((:coalton-file "arith")
(:coalton-file "num")
(:coalton-file "bounded")
(:file "conversions")
(:file "fraction")
(:file "integral")
Expand Down
60 changes: 60 additions & 0 deletions library/builtin.coal
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
(package coalton-library/builtin
(import
coalton-library/classes)
(export
unreachable
undefined
error ; re-export from classes
not
xor
boolean-not
boolean-or
boolean-and
boolean-xor))

(lisp-toplevel ()
(cl:eval-when (:compile-toplevel)
(cl:defmacro unreachable (cl:&optional (datum "Unreachable") cl:&rest arguments)
"Signal an error with CL format string DATUM and optional format arguments ARGUMENTS."
`(lisp :a ()
(cl:error ,datum ,@arguments)))))

(define (undefined _)
"A function which can be used in place of any value, throwing an error at runtime."
(error "Undefined"))

(define not
"Synonym for `boolean-not`."
boolean-not)

(define xor
"Synonym for `boolean-xor`."
boolean-xor)

(declare boolean-not (Boolean -> Boolean))
(define (boolean-not x)
"The logical negation of `x`. Is `x` false?"
(match x
((True) False)
((False) True)))

(declare boolean-or (Boolean -> Boolean -> Boolean))
(define (boolean-or x y)
"Is either `x` or `y` true? Note that this is a *function* which means both `x` and `y` will be evaluated. Use the `or` macro for short-circuiting behavior."
(match x
((True) True)
((False) y)))

(declare boolean-and (Boolean -> Boolean -> Boolean))
(define (boolean-and x y)
"Are both `x` and `y` true? Note that this is a *function* which means both `x` and `y` will be evaluated. Use the `and` macro for short-circuiting behavior."
(match x
((True) y)
((False) False)))

(declare boolean-xor (Boolean -> Boolean -> Boolean))
(define (boolean-xor x y)
"Are `x` or `y` true, but not both?"
(match x
((True) (boolean-not y))
((False) y)))
71 changes: 0 additions & 71 deletions library/builtin.lisp

This file was deleted.

Loading

0 comments on commit d5bd300

Please sign in to comment.