amkhlv
amkhlv

Reputation: 337

Structure of X-expression in Racket

Racket represents XML data as an X-expression: http://docs.racket-lang.org/xml/index.html?q=#(def._((lib._xml/private/xexpr-core..rkt)._xexpr~3f)) which is defined as follows:

xexpr    =      string
        |       (list symbol (list (list symbol string) ...) xexpr ...)
        |       (cons symbol (list xexpr ...))
        |       symbol
        |       valid-char?
        |       cdata
        |       misc

In the second alternative, why is it (list symbol string) and not (cons symbol string) ? Is there any specific reason to use list instead of cons ? If not, would there be any advantage in using cons instead of list ?

Upvotes: 2

Views: 988

Answers (1)

C. K. Young
C. K. Young

Reputation: 223003

It's really just a preference on the part of the X-expression designers, probably to mirror let's syntax (which also uses proper lists only).

With (list symbol string), you'd represent <a href="http://stackoverflow.com/">Stack Overflow</a> as:

(a ((href "http://stackoverflow.com/")) "Stack Overflow")

whereas with (cons symbol string), it'd be:

(a ((href . "http://stackoverflow.com/")) "Stack Overflow")

Some would consider the "dot" an ugly thing to see.

Upvotes: 3

Related Questions