forked from coalton-lang/coalton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.lisp
26 lines (23 loc) · 1.02 KB
/
utils.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(cl:defpackage #:coalton-library/utils
(:use #:coalton)
(:export #:defstdlib-package #:generate-unary-wrapper))
(cl:in-package #:coalton-library/utils)
(cl:defmacro defstdlib-package (name cl:&rest args)
`(cl:eval-when (:compile-toplevel :load-toplevel)
#+sb-package-locks
(cl:when (cl:find-package ',name)
(sb-ext:unlock-package ',name))
(cl:defpackage ,name ,@args)
#+sb-package-locks
(sb-ext:lock-package ',name)))
(cl:defun generate-unary-wrapper
(return-type coalton-fun cl-fun cl:&key
domain)
"Returns the definition of a coalton function which is a unary wrapper around a corresponding CL function. Takes an optional domain, which is a symbol evaluating to a function, which returns true iff if a value is in the domain"
`(define (,coalton-fun x)
(lisp ,return-type (x)
,(cl:when domain
`(cl:unless (cl:funcall ,domain x)
(cl:error "~a is not in the domain of ~a for ~a"
x ',coalton-fun ',return-type)))
(,cl-fun x))))