Re: feature of attribute building: automatic joining of (cdr attribute-list)
[email protected] Mon, 12 Jul 2004 22:11:24 -0700 (PDT)
| Newsgroups | gmane.lisp.scheme.ssax-sxml |
|---|---|
| Message-ID | <[email protected]> |
Hello!
> (cvs-ref
> *macro*
> . ,(lambda (tag path)
> `(a (@ (href
> "http://cvs.sourceforge.net/viewcvs.py/kanren/kanren/"
> ,path))
> (code ,path))))
> It appears that an attribute is built from a list.
Indeed. The rule for building attributes in SSAX/lib/SXML-to-HTML.scm
says
(*default* ; local override for attributes
. ,(lambda (attr-key . value) (enattr attr-key value)))
so there may be 0, 1, or more list elements after attr-key.
> (define (enattr attr-key value)
> (if (null? value) (list #\space attr-key)
> (list #\space attr-key "=\"" value #\")))
If there is at least one element after attr-key, they are all
concatenated together in the output. One may ask where is the
list concatenation in the above code for enattr. It is implicit:
SRV:send-reply will do the `concatenation'. To be precise, the latter
will traverse inside the 'value' and write out the corresponding
pieces in order. So, we never have to do any concatenation
explicitly, which saves time. This is quite analogous to
scatter/gather kind of IO in Unix (X/Open) (cf. XPG4.2 function
`writev').
In my XML code (and I believe in sxmlcnv) the corresponding rule reads
; Attributes with the #f value are dropped
(define (enattr attr-key value)
(and value (list #\space attr-key "='" value #\')))
so our SXML code may have
`(p (@ (style ,(get-style))) "text")
where get-style may return a string or #f. In the latter case, no
style attribute will be generated (and the `p' element would have no
attributes at all). This is quite convenient.
> 2/ I notice that the *macro* qualifier was used when rewriting a cvs-ref
> tag. Correct me if I'm wrong, but I believe the reason this is done is
> so that the code tag can be properly expanded.
That is correct. cvs-ref is a second-order tag:
(cvs-ref path)
gets re-written into
(a (@ (href ...)) ...)
which gets re-written into
("<a " "href=" "..." ">" ... "</a>")
which is in the normal form and simply gets written out.
The *macro* "tag" in SXLST is indeed akin to macros. Actually, it is
akin to expansion-passing macros. I believe WebIt uses the same
technique.
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit www.blackhat.com