Coverage report: /home/runner/work/geb/geb/src/specs/poly.lisp
Kind | Covered | All | % |
expression | 10 | 55 | 18.2 |
branch | 0 | 0 | nil |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
1
(in-package #:geb.poly.spec)
4
`(or compose + * / - mod integer if-zero if-lt ident))
6
(defclass <poly> (geb.mixins:direct-pointwise-mixin) ())
8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9
;; Constructor Objects for Poly
10
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12
(defclass compose (<poly>)
16
(mcadr :initarg :mcadr
24
(mcadr :initarg :mcadr
28
(defclass ident (<poly>)
30
(:documentation "The Identity Element"))
36
(mcadr :initarg :mcadr
44
(mcadr :initarg :mcadr
52
(mcadr :initarg :mcadr
56
(defclass mod (<poly>)
60
(mcadr :initarg :mcadr
64
(defclass if-zero (<poly>)
65
((predicate :initarg :predicate
74
(:documentation "compare with zero: equal takes first branch;
75
not-equal takes second branch"))
76
(defclass if-lt (<poly>)
80
(mcadr :initarg :mcadr
90
"If the [MCAR] argument is strictly less than the [MCADR] then the
91
[THEN] branch is taken, otherwise the [ELSE] branch is taken."))
93
(defmethod mcar ((obj if-zero))
96
(defmethod mcadr ((obj if-zero))
99
(defmethod mcaddr ((obj if-zero))
102
(defmethod mcaddr ((obj if-lt))
105
(defmethod mcadddr ((obj if-lt))
108
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
110
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
112
(defmacro make-multi (constructor)
113
`(defun ,constructor (mcar mcadr &rest args)
114
,(format nil "Creates a multiway constructor for [~A]" constructor)
115
(reduce (lambda (x y)
116
(make-instance ',constructor :mcar x :mcadr y))
117
(list* mcar mcadr args)
126
(defun mod (mcar mcadr)
128
(make-instance 'mod :mcar mcar :mcadr mcadr))
130
(defun if-zero (pred then else)
131
"checks if [PREDICATE] is zero then take the [THEN] branch otherwise
133
(make-instance 'if-zero :predicate pred :then then :else else))
135
(defun if-lt (mcar mcadr then else)
136
"Checks if the [MCAR] is less than the [MCADR] and chooses the appropriate branch"
137
(make-instance 'if-lt :mcar mcar :mcadr mcadr :then then :else else))
139
(serapeum:def ident (make-instance 'ident))
141
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
143
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
145
;; Ι don't do multi way pattern matching yet :(
146
(make-pattern + mcar mcadr)
147
(make-pattern * mcar mcadr)
148
(make-pattern / mcar mcadr)
149
(make-pattern - mcar mcadr)
150
(make-pattern compose mcar mcadr)
151
(make-pattern mod mcar mcadr)
152
(make-pattern if-zero predicate then else)
153
(make-pattern if-lt mcar mcadr then else)