Plaster
New
List
Login
common-lisp
default
anonymous
2022.12.13 22:35:49
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; a.lisp (defpackage #:deftype-tests (:use :common-lisp)) (in-package #:deftype-tests) (defmacro def-sums-to (name &key (amount 10)) "Defines a def-sums-to type." (let ((functor-sym (gensym (format nil "SUMS-TO-~A-" amount)))) `(progn (eval-when (:load-toplevel :compile-toplevel :execute) (defun ,functor-sym (list) (= (loop for item in list sum item) ,amount))) (deftype ,name () '(satisfies ,functor-sym))))) (def-sums-to twelve-list :amount 12) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; b.lisp (in-package #:deftype-tests) (declaim (ftype (function (twelve-list) number) sum-twelve)) (defun sum-twelve (list) (declare (ignore list)) 12) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; compile-and-load a.lisp ;;;; compile-and-load b.lisp ;;;; then, in the REPL: CL-USER> (lisp-implementation-type) "SBCL" CL-USER> (lisp-implementation-version) "2.2.9" CL-USER> (deftype-tests::sum-twelve '()) The function #:SUMS-TO-12-0 is undefined. [Condition of type UNDEFINED-FUNCTION] Restarts: 0: [CONTINUE] Retry calling #:SUMS-TO-12-0. 1: [USE-VALUE] Call specified function. 2: [RETURN-VALUE] Return specified values. 3: [RETURN-NOTHING] Return zero values. 4: [RETRY] Retry SLIME REPL evaluation request. 5: [*ABORT] Return to SLIME's top level. --more-- Backtrace: 0: ("undefined function" NIL) 1: (DEFTYPE-TESTS::SUM-TWELVE NIL) [external]
Raw
Annotate
Repaste
Edit