[Top][All Lists]

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

Re: [dev-serveez] guile support

From: Martin Grabmueller
Subject: Re: [dev-serveez] guile support
Date: Tue, 05 Feb 2002 12:42:31 +0100

> From: stefan <address@hidden>
> Date: Mon, 4 Feb 2002 21:12:20 +0100 (CET)
> ============= 8< ======================================================
> ;; checks whether the rpc service identified by [number,version] is
> ;; already register at the portmapper and return #t if so.  otherwise 
> ;; the procedure return #f.
> (define (check-rpc-portmapper number version)
>   (let* ((mappings (portmap-list)) (result #f))
>     (if mappings
>         (for-each (lambda (mapping)
>                     (if (and (equal? (vector-ref mapping 0) number)
>                              (equal? (vector-ref mapping 1) version))
>                         (set! result #t)))
>                   mappings))
>     result))
> ============= >8 ======================================================

(define (check-rpc-portmapper number version)
  (let ((mappings (portmap-list)))
    (and mappings
         (let loop ((m mappings))
            (if (null? m)
                (or (and (equal? (vector-ref (car m) 0) number)
                         (equal? (vector-ref (car m) 1) version))
                    (loop (cdr m))))))))

Don't know whether is nicer...  The (and mappings ...) part checks
whether mappings is #f, and returns #f if it is.  The (let loop
((...)) ...) thingy is a loop which walks down the list of mappings
(which are named m for brevity inside the loop).  When the end of list
is reached, #f is returned, otherwise the (or ...) tests whether the
actual element of m matches or any of the remaining elements of the

At least, this should match the spec.  Attention: Not tested though.


reply via email to

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