<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>There is also an XML representation and it uses structs for some nodes in the representation. But as Carl says, once they are S-expressions, it is easy to use regular list functionality for traversals and construction. See 2e -- Matthias</div><div><br></div><div><br></div><br><div><div>On Jun 11, 2013, at 1:08 PM, Matthew Butterick wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">To ask an abstract question: is there a particular reason that X-expressions are defined in Racket as a special kind of S-expression, rather than a struct or primitive datatype?</div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Tue, Jun 11, 2013 at 6:46 AM, Matthias Felleisen <span dir="ltr"><<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
You may have been speaking abstractly but the point is that it is a mostly accurate summary of Xexpr and I use just this form in HtDP/2e to process X-expressions. -- Matthias<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
On Jun 10, 2013, at 3:27 PM, Jay McCarthy wrote:<br>
<br>
> I wasn't referencing the docs. I'm just talking abstractly. The point<br>
> is that you have to consider the attribute list as a totally different<br>
> kind of thing. The thing you cite can be directly turned into a match<br>
> pattern, though:<br>
><br>
> (match xe<br>
> [(? string? s) ....]<br>
> [(list (? symbol? tag) (list (list (? symbol? k) (? string? v)) ...) xe ...)<br>
> ....]<br>
> [(cons (? symbol? tag) (list xe ...))<br>
> ...]<br>
> etc<br>
><br>
> On Mon, Jun 10, 2013 at 1:20 PM, Matthew Butterick<br>
> <<a href="mailto:mb.list.acct@gmail.com">mb.list.acct@gmail.com</a>> wrote:<br>
>> Aha, the xexpr-drop-empty-attributes is probably best, since it will produce<br>
>> consistent forms. Thanks.<br>
>><br>
>> BTW what part of the docs are you citing for (list* Symbol (option<br>
>> AttributeList) XexprList)? The only definition of X-expressions I'm aware of<br>
>> is here.<br>
>><br>
>><br>
>> On Mon, Jun 10, 2013 at 11:58 AM, Jay McCarthy <<a href="mailto:jay.mccarthy@gmail.com">jay.mccarthy@gmail.com</a>><br>
>> wrote:<br>
>>><br>
>>> The type of Xexpr is...<br>
>>> | AtomicContent<br>
>>> | (list* Symbol (option AttributeList) XexprList)<br>
>>><br>
>>> It sounds like you have one function F that you would like to give the<br>
>>> type "Xexpr -> Value", but you are having a problem when you apply it<br>
>>> to the AttributeList. You should have such a problem, because an<br>
>>> AttributeList is not an Xexpr, so your types are wrong.<br>
>>><br>
>>> In other words, if you want to recursively process an Xexpr, then you<br>
>>> need two functions, one for attribute lists and one for xexpr lists.<br>
>>><br>
>>> Finally, I find it convenient when automatically processing Xexprs to<br>
>>> ensure that xexpr-drop-empty-attributes is #f so that there is always<br>
>>> an attribute list and do:<br>
>>><br>
>>> (match xe<br>
>>> [(list* tag attrs content) ....])<br>
>>><br>
>>><br>
>>><br>
>>> On Mon, Jun 10, 2013 at 12:40 PM, Matthew Butterick<br>
>>> <<a href="mailto:mb.list.acct@gmail.com">mb.list.acct@gmail.com</a>> wrote:<br>
>>>> Consider an x-expression that represents an XML tag, so it has the<br>
>>>> general<br>
>>>> form<br>
>>>><br>
>>>> '(tag ((attr-name "attr-value") ... ) content ...)<br>
>>>><br>
>>>> The attributes or content might be omitted, of course.<br>
>>>><br>
>>>> When I recursively process these expressions, I start by decomposing the<br>
>>>> x-expression into components:<br>
>>>><br>
>>>> tag<br>
>>>> ((attr-name "attr-value") ... )<br>
>>>> (content ...)<br>
>>>><br>
>>>> The problem that surfaces in a recursive-processing context is that the<br>
>>>> list<br>
>>>> of content might have the same form as an attribute expression, e.g.,<br>
>>>><br>
>>>> ((field-1 "value-1") (field-2 "value-2"))<br>
>>>> ((p "some text") (p "some more text"))<br>
>>>><br>
>>>> Is there a test I could use to reliably disambiguate between these two<br>
>>>> cases, short of creating a new struct for x-expressions? Seems like I'm<br>
>>>> overlooking some middle ground.<br>
>>>><br>
>>>><br>
>>>><br>
>>>> ____________________<br>
>>>> Racket Users list:<br>
>>>> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
>>>><br>
>>><br>
>>><br>
>>><br>
>>> --<br>
>>> Jay McCarthy <<a href="mailto:jay@cs.byu.edu">jay@cs.byu.edu</a>><br>
>>> Assistant Professor / Brigham Young University<br>
>>> <a href="http://faculty.cs.byu.edu/~jay" target="_blank">http://faculty.cs.byu.edu/~jay</a><br>
>>><br>
>>> "The glory of God is Intelligence" - D&C 93<br>
>><br>
>><br>
>><br>
>> ____________________<br>
>> Racket Users list:<br>
>> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
>><br>
><br>
><br>
><br>
> --<br>
> Jay McCarthy <<a href="mailto:jay@cs.byu.edu">jay@cs.byu.edu</a>><br>
> Assistant Professor / Brigham Young University<br>
> <a href="http://faculty.cs.byu.edu/~jay" target="_blank">http://faculty.cs.byu.edu/~jay</a><br>
><br>
> "The glory of God is Intelligence" - D&C 93<br>
> ____________________<br>
> Racket Users list:<br>
> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br>
</div></div></blockquote></div><br></div>
____________________<br> Racket Users list:<br> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></div><br></body></html>