aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-04-02 16:10:04 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-04-02 16:13:32 -0700
commit76c3ac60450fb144bf6cfd0fb4197b91af5a3f87 (patch)
treee243c625c95625cd3ac7635b9ff764037eb86a73 /src
parentfc6d35b5bf33d6a5fcba9c44a769e653fa6712fa (diff)
downloadconsfigurator-76c3ac60450fb144bf6cfd0fb4197b91af5a3f87.tar.gz
factor out DEFINE-CHOOSING-PROPERTY-COMBINATOR
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src')
-rw-r--r--src/combinator.lisp18
-rw-r--r--src/package.lisp1
-rw-r--r--src/property/os.lisp35
3 files changed, 30 insertions, 24 deletions
diff --git a/src/combinator.lisp b/src/combinator.lisp
index ee70d62..3c1d21d 100644
--- a/src/combinator.lisp
+++ b/src/combinator.lisp
@@ -33,6 +33,24 @@
(return-from ,name (list* psym args)))))
,@forms))))
+(defmacro define-choosing-property-combinator
+ (name lambda-list &key type choose)
+ `(define-function-property-combinator ,name ,lambda-list
+ (flet ((choose-propapp () ,choose))
+ (:retprop :type ,type
+ :desc (lambda (&rest args)
+ (declare (ignore args))
+ (propappdesc (choose-propapp)))
+ :hostattrs (lambda (&rest args)
+ (declare (ignore args))
+ (propappattrs (choose-propapp)))
+ :apply (lambda (&rest args)
+ (declare (ignore args))
+ (propappapply (choose-propapp)))
+ :unapply (lambda (&rest args)
+ (declare (ignore args))
+ (propappunapply (choose-propapp)))))))
+
(defmacro with-skip-failed-changes (&body forms)
`(handler-bind ((failed-change
(lambda (c)
diff --git a/src/package.lisp b/src/package.lisp
index 24e4b2a..c870ad2 100644
--- a/src/package.lisp
+++ b/src/package.lisp
@@ -144,6 +144,7 @@
;; combinator.lisp
#:define-function-property-combinator
+ #:define-choosing-property-combinator
#:seqprops
#:eseqprops
#:with-requirements
diff --git a/src/property/os.lisp b/src/property/os.lisp
index 934dec8..04ac5ab 100644
--- a/src/property/os.lisp
+++ b/src/property/os.lisp
@@ -83,30 +83,17 @@
;;;; Property combinators
-(define-function-property-combinator os-etypecase* (host &rest cases)
- (flet ((choose-propapp ()
- (or (loop with os = (class-of (if host
- (car (getf (hostattrs host) :os))
- (get-hostattrs-car :os)))
- for (type propapp) on cases by #'cddr
- when (subtypep os type) return propapp)
- (inapplicable-property
- "Host's OS ~S fell through OS:ETYPECASE."
- (class-of (get-hostattrs-car :os))))))
- (:retprop :type (collapse-types (loop for propapp in (cdr cases) by #'cddr
- collect (propapptype propapp)))
- :desc (lambda (&rest args)
- (declare (ignore args))
- (propappdesc (choose-propapp)))
- :hostattrs (lambda (&rest args)
- (declare (ignore args))
- (propappattrs (choose-propapp)))
- :apply (lambda (&rest args)
- (declare (ignore args))
- (propappapply (choose-propapp)))
- :unapply (lambda (&rest args)
- (declare (ignore args))
- (propappunapply (choose-propapp))))))
+(define-choosing-property-combinator os-etypecase* (host &rest cases)
+ :type (collapse-types (loop for propapp in (cdr cases) by #'cddr
+ collect (propapptype propapp)))
+ :choose (or (loop with os = (class-of (if host
+ (car (getf (hostattrs host) :os))
+ (get-hostattrs-car :os)))
+ for (type propapp) on cases by #'cddr
+ when (subtypep os type) return propapp)
+ (inapplicable-property
+ "Host's OS ~S fell through OS:ETYPECASE."
+ (class-of (get-hostattrs-car :os)))))
(defmacro etypecase (&body cases)
`(host-etypecase nil ,@cases))