by lisper · 11y ago · 0 comments
<foo bar="zot">quux</foo>
should be read as
(foo (bar "zot") "quux")
and most definitely _NOT_ as ((:foo :bar "zot") "quux")
Erik has this exactly backwards. His rendering is ambiguous: it does not distinguish <foo bar="zot"/> from <foo><bar>zot</bar></foo> (as he himself implicitly acknowledges later in the post). Also, rendering unqualified tags as keywords makes it easier to deal with namespaces.IMHO the Right Way to render <foo bar="zot">quux</foo> is ((:foo :bar "zot") "quux") with the further qualification that if there are no tags then ((:foo) "quux") can be simplfied to (:foo "quux"). This preserves a 1-1 correspondence between XML and sexprs, which is IMHO a requirement (in fact, the only requirement) for a reasonable mapping. If you have a 1-1 correspondence then you can freely convert back and forth between the two. If you don't, then you can't.
No matter how you slice it, Erik is wrong here. His translation is lossy, and a lossy translation is bad because it can't be applied bidirectionally.
His very first sentence is:
As long as we think aloud in alternative syntaxes, I actually prefer to
break the _incredibly_ stupid syntactic-only separation of elements and
attribute values.
His entire post is a hypothetical in which you 1) need a structured markup language and 2) are willing to break compatibility with XML.<input type=button/>
and
<input><type>button</type></input>
Tags compose in different ways than attributes, that difference reflects a real aspect of the structure of the problem, and hence it's useful.
https://groups.google.com/d/msg/comp.lang.lisp/8eUxiibm_zA/i...
"Whether bar is an attribute or a sub-element of foo is irrelevant to processing them."
I disagree. Elements and attributes compose in different ways, and I think this distinction is useful and hence relevant. I think it is self-evident that:
<input type=button/>
and
<input><type>button</type></input>
mean different things, and that it is legitimate to try to express either of these things, and so distinguishing between these two different things is useful.
In particular, the latter representation implies that:
<input>foo</input> <type>bar</type>
might mean something. The former representation makes it explicit that the type attribute is intended to be inextricably bound to the input tag. I think that's useful information.
Alternatively you could also write (foo ((bar "zot)) quux) as it is handled in Racket's X-expressions, which has the distinct advantage that the symbol/identifier foo is not nested one level deeper, which makes reading it harder, while still preserving the 1-1 correspondence. Though in this case the meta-information is the first argument instead of being part of the identifier. It also works perfectly with stuff like <foo bar="zot" baz="zor">quux</foo>, which is read as (foo ((bar zot) (baz zor)) quux). I personally think this is way better than ((:foo :bar "zot" :baz "zor) "quux")
Why is that an advantage?
I actually like the aesthetics of the extra parens in the CAR. It provides a clear visual distinction between code and markup (at least in Common Lisp, where ((...) ...) is defined by the standard to be a syntax error) which I think is a feature. e.g.:
((:div :class "toplevel" :style "display:block")
(:h1 "This is a heading")
"This is content")
I think it looks kinda nice.You are correct that:
<foo bar="zot">quux</foo> => (foo (bar "zot"))
<foo><bar>zot</bar></foo> => (foo (bar "zot"))
Is an ambiguity. However in his <|> syntax: <foo bar="zot">quux</foo> => <foo <bar | "zot">>
<foo><bar>zot</bar></foo> => <foo | <bar | "zot">>
What about, say: <foo bar="zot">quux</foo>
as (foo (bar "zot") (data "quux"))
Or any other keyword which you could reserve as being the special "non-meta" data? (foo (bar "zot")) is then unambiguously <foo bar="zot"/>
(foo (data (bar "zot"))) is then <foo><bar>zot</bar></foo>
I'm not sure whose side I'm on by proposing this. I'd be interested to know."Whether something is an attribute or element is _completely_ arbitrary."
THAT is the point on which he is (IMHO) clearly wrong. (He's wrong about a bunch of other things too, but that's the most serious mistake.)
EDIT: Here is Erik doubling down on his position:
"I have a simple way to get rid of the annoying verbosity of these stupid languages while _retaining_ that mistake [sic] between attribute values and elements"
He does not appear to make an argument as to why he believes this, so I'd say his claim is at worst unsubstantiated.
I find it hard to believe that there's a objectively correct decision about the number of semantic concepts that "should" be encoded in a syntax, but I can understand why lisp enthusiasts would be on the 'closer-to-none end of that spectrum.
I'd be interested to hear why you think it's so essential. The only argument I'm really aware of is compatibility with existing markup languages.
I would guess that a markup syntax that is as simple and regular (ie. syntactically consistent) as possible would be the easiest to operate on algorithmically. I would also guess that this would make it easier to build, on top of this language, tools which present the content in various ways that are easier to read/write/manually-manipulate if you so desired.
Actually, his example syntax makes this argument implicitly. He is suggesting that his tools are significantly easier to implement by working with plain S-Expressions, and that they can easily be mapped to a 'write-friendly markup language that is isomorphic to XML anyway.
I make no claims about the quality of his presentation or the clarity of his arguments.
The <|> syntax is also absolutely non-ambiguous.
It seems to me that the fact that people can't even agree whether he actually meant P or ~P ought to call his wisdom (or at least his ability to communicate) into question.
I'm fairly certain that the reason he handles the pathological cases is so that he may interface with other people's XML specs. One can hate the design while meaningfully working with others, right?
By the way, it is an S expression. He uses the empty symbol || as a delimiter for the pathological cases. Furthermore, the Enamel syntax he describes is a reader macro; whether you think that is OK is up to your own personal aesthetics, but it is just an alternative syntax for lists (not everything has to syntactically be an S-expression, after all).
You (lisper) keep mentioning that there is a distinction between metadata and data, and you mention that composibility is the big distinction. However, as far as I can tell, you can compose child elements in an ordered sequence which you can't do with attributes (though you can append sets of attributes as sets), and you can't nest attributes. It seems to me that the only reason for everything not to be elements is that they take longer to type with XML syntax. Also, child elements are in some sense just attributes with implicit numeric keys, if attributes could be data other than strings.
What is an example of this distinction between attributes and elements which is not just syntax?
Yes. And I'm saying he's wrong. Not only is he wrong, he's clearly wrong. Not only is it not "incredibly stupid", the distinction between attributes and elements is both reasonable and useful. And the reason it's reasonable and useful is because it reflects a reasonable and useful distinction between data and metadata.
> What is an example of this distinction between attributes and elements which is not just syntax?
I don't understand that question.
My claim is that, in the context of markup languages, there is a useful distinction to be made between data and metadata, and that this distinction is useful enough that it is not unreasonable to make this distinction syntactically. Of course, it doesn't have to be made syntactically. In Lisp, there is no syntactic difference between function calls and control constructs. Consider:
(foo (baz bar) bing)
Is (bar bar) a function call? If FOO is a macro that expands to:
(dotimes (baz bar) bing)
then BAZ is a variable binding. Arguably, it would be worthwhile to make a syntactic distinction here. For example, you could use square brackets for variable bindings, so that you could tell that in:
(foo [baz bar] bing)
BAZ was a variable binding without having to know how FOO was defined. It's not a slam dunk, but it is a defensible position.
Likewise, it is a defensible position that the difference between <foo baz=bar>bing</foo> and <foo><baz>bar</baz></foo> -- whatever that difference might actually be in practice -- is valuable and ought to be preserved. Again, not a slam-dunk, but a defensible position.
What makes Erik clearly wrong is this his rendering of <foo baz=bar>bing</foo> is NOT actually any simpler than a rendering that preserves the attribute/element distinction. His rendering has EXACTLY the same level of nesting, the same number of tokens. The ONLY difference is the location of a paren. And the way he moves the paren, he loses information. Without a compelling argument why moving that paren has more value than the information that he loses, that paren ought not to be moved. All else being equal (and in this case all else is equal) it is better to keep information than to lose it. Not only does Erik not make a compelling argument, he makes no argument at all. He simply proclaims that it is "incredibly stupid" and his acolytes, for reasons passing my comprehension, agree.