I've been developing a Scheme editing mode, and I have a question
about the syntax that SXML uses for attributes. When embedding literal
XML in code using quoted s-exps, the syntax for attributes uses an @
symbol in the head position, like so:
'(opf:package
(@ (version "2.0")
... etc etc ...
My mode marks this as an error, because according to R5RS identifiers
can't begin with an @. How does this work? Is this considered an
extension that Scheme implementations just accept or are the rules
different for quoted literals? I can't see anything in the R5RS
grammar that would suggest that though.
Thanks for any advice,
Colin
I believe that virtually all Scheme implementations that support R5RS
have also supported reading "@" as a symbol for years. (At least one
Scheme implementation did not originally, but then did, specifically
because of SXML.)
For this reason, I see nothing to be gained by prohibiting "@" in 'R5RS'
code.
R6RS might be a different story; I haven't used it enough to say.
Great, thanks. I just wanted to check what the situation was.
Cheers,
Colin
In R[456]RS, symbols cannot begin with @. As I was told [1], the
reason for that is:
If @ were permitted as the initial character of an identifier,
then it would be ambiguous whether {,@foo} and {,@ foo} were
unquotes or splicing unquotes.
That's a solid reason for why SXML, or anything, should not use an @
symbol. If we want to use symbols which start with @, the syntax for
unquote and unquote-splicing needs to be changed.
I've ported SSAX, sxml-tools, sxml-match, and htmlprag [2] to R6RS. I
modified all of them to use ^ instead of @ [3], but otherwise they're
the original code, named and structured as libraries very similarly to
the original files. My ports include all the (many) original tests,
and they all pass. I encourage others to use ^. I think of ^ as the
top half of an A which is the first character of the word attributes.
I think ^ looks good:
((p (br))
(table
(^ (bgcolor "#CCCCCC") (width "100%") (cellpadding "3"))
(tr (td ("KMRY, MONTEREY PENINSULA"))
(td "Id: " ("724915"))
(td "[" ("36.583, -121.850") "]")))
(table
(^ (width "100%") (cellpadding "1") (BORDER "1")
(RULES "none") (FRAME "hsides"))
(tr
(td (^ (width "20%")) (5 "-" 11 " " 17 ":" 30) (br)
((11 " " 18 ":" 0) " - " (11 " " 18 ":" 0)))
(td ("111730Z 111818")
((div (^ (class "per_nc")) () " "
("31010KT P6SM FEW030"))
(div (^ (class "per_c")) ("FM2100") " "
("29016KT P6SM FEW040"))
(div (^ (class "per_nc")) ("FM0400") " "
("29010KT P6SM SCT200"))
(div (^ (class "var")) ("BECMG 0708") " "
("VRB05KT")))))))
[1] http://lists.r6rs.org/pipermail/r6rs-discuss/2008-June/003518.html
[2] https://code.launchpad.net/~derick-eddington/scheme-libraries/xitomatl
[3] http://sourceforge.net/mailarchive/forum.php?thread_name=1214378777.31858.90.camel%40eep&forum_name=ssax-sxml
--
: Derick
----------------------------------------------------------------
Thanks, that's interesting, I must admit I was surprised when I looked
at the spec. I hadn't thought of the splicing problem, although I'm
guessing in practice it's not much of a problem given that SXML seems
to be pretty widespread. I can imagine it's probably inconsistently
handled across implementations though. I quite like the hat notation,
I guess the main problem is incompatibility with existing code,
although migrating it should be pretty easy. Do you use ^^ instead of
@@ as well?
Cheers,
Colin
Yes.
--
: Derick
----------------------------------------------------------------