guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[shepherd] 02/03: service: Improve style of 'lookup-running-or-providing


From: Ludovic Courtès
Subject: [shepherd] 02/03: service: Improve style of 'lookup-running-or-providing'.
Date: Wed, 13 Jan 2016 22:49:05 +0000

civodul pushed a commit to branch master
in repository shepherd.

commit a906cbb5a01028c8836c3601940f5f8153cf2811
Author: Ludovic Courtès <address@hidden>
Date:   Wed Jan 13 22:17:18 2016 +0100

    service: Improve style of 'lookup-running-or-providing'.
    
    * modules/shepherd/service.scm (lookup-running-or-providing): Rewrite
    using 'match'.
    (service?): New procedure.
---
 modules/shepherd/service.scm |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index f50e328..b5da166 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -31,6 +31,7 @@
   #:replace (system
              system*)
   #:export (<service>
+            service?
             canonical-name
             running?
             action-list
@@ -158,6 +159,10 @@ respawned, shows that it has been respawned more than 
TIMES in SECONDS."
   ;; The times of the last respawns, most recent first.
   (last-respawns #:init-form '()))
 
+(define (service? obj)
+  "Return true if OBJ is a service."
+  (is-a? obj <service>))
+
 (define action:name car)
 (define action:proc cadr)
 (define action:doc cddr)
@@ -542,11 +547,11 @@ clients."
 ;; one-element list.  If none is running, return a list of all
 ;; services which provide SYM.
 (define (lookup-running-or-providing sym)
-  (define (list-unless-false x)
-    (if x (list x) x))
-
-  (or (list-unless-false (lookup-running sym))
-      (lookup-services sym)))
+  (match (lookup-running sym)
+    ((? service? service)
+     (list service))
+    (#f
+     (lookup-services sym))))
 
 
 ;;;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]