Re: Testing if an attribute is present

Subject: Re: Testing if an attribute is present
From: Paul Prescod <papresco@xxxxxxxxxxxxxxxx>
Date: Mon, 27 Oct 1997 12:58:06 -0500
Vivek Agrawala wrote:
> Here is a procedure that illustrates how to check for an attribute:
> 
> (define (get-str-attr-no-err attr-nm snl)
>   (let ((a-str (attribute-string attr-nm snl)))
>     (if (equal? a-str #f) "" a-str) ))
> 
> To use it:
>  (get-str-attr-no-err "DAY" (current-node))

A nice idiom I've seen would be a good extension to your function:

(define (get-str-attr-no-err attr-nm #!optional (osnl (current-node))
#!key (default "") )
  (let ((a-str (attribute-string attr-nm osnl)))
    (if (equal? a-str #f) key a-str) ))

Then you can call the function like this:

(get-str-attr-no-err "DAY" default: "Sunday" )

But first you'll have to fix the typos in my untested code above. :)

 Paul Prescod



 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist


Current Thread