<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">&lt;<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>&gt;</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>
&gt; I wasn&#39;t referencing the docs. I&#39;m just talking abstractly. The point<br>
&gt; is that you have to consider the attribute list as a totally different<br>
&gt; kind of thing. The thing you cite can be directly turned into a match<br>
&gt; pattern, though:<br>
&gt;<br>
&gt; (match xe<br>
&gt; [(? string? s) ....]<br>
&gt; [(list (? symbol? tag) (list (list (? symbol? k) (? string? v)) ...) xe ...)<br>
&gt;  ....]<br>
&gt; [(cons (? symbol? tag) (list xe ...))<br>
&gt;  ...]<br>
&gt; etc<br>
&gt;<br>
&gt; On Mon, Jun 10, 2013 at 1:20 PM, Matthew Butterick<br>
&gt; &lt;<a href="mailto:mb.list.acct@gmail.com">mb.list.acct@gmail.com</a>&gt; wrote:<br>
&gt;&gt; Aha, the xexpr-drop-empty-attributes is probably best, since it will produce<br>
&gt;&gt; consistent forms. Thanks.<br>
&gt;&gt;<br>
&gt;&gt; BTW what part of the docs are you citing for (list* Symbol (option<br>
&gt;&gt; AttributeList) XexprList)? The only definition of X-expressions I&#39;m aware of<br>
&gt;&gt; is here.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Mon, Jun 10, 2013 at 11:58 AM, Jay McCarthy &lt;<a href="mailto:jay.mccarthy@gmail.com">jay.mccarthy@gmail.com</a>&gt;<br>
&gt;&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; The type of Xexpr is...<br>
&gt;&gt;&gt; | AtomicContent<br>
&gt;&gt;&gt; | (list* Symbol (option AttributeList) XexprList)<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; It sounds like you have one function F that you would like to give the<br>
&gt;&gt;&gt; type &quot;Xexpr -&gt; Value&quot;, but you are having a problem when you apply it<br>
&gt;&gt;&gt; to the AttributeList. You should have such a problem, because an<br>
&gt;&gt;&gt; AttributeList is not an Xexpr, so your types are wrong.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; In other words, if you want to recursively process an Xexpr, then you<br>
&gt;&gt;&gt; need two functions, one for attribute lists and one for xexpr lists.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Finally, I find it convenient when automatically processing Xexprs to<br>
&gt;&gt;&gt; ensure that xexpr-drop-empty-attributes is #f so that there is always<br>
&gt;&gt;&gt; an attribute list and do:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; (match xe<br>
&gt;&gt;&gt; [(list* tag attrs content) ....])<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On Mon, Jun 10, 2013 at 12:40 PM, Matthew Butterick<br>
&gt;&gt;&gt; &lt;<a href="mailto:mb.list.acct@gmail.com">mb.list.acct@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt; Consider an x-expression that represents an XML tag, so it has the<br>
&gt;&gt;&gt;&gt; general<br>
&gt;&gt;&gt;&gt; form<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &#39;(tag ((attr-name &quot;attr-value&quot;) ... ) content ...)<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; The attributes or content might be omitted, of course.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; When I recursively process these expressions, I start by decomposing the<br>
&gt;&gt;&gt;&gt; x-expression into components:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; tag<br>
&gt;&gt;&gt;&gt; ((attr-name &quot;attr-value&quot;) ... )<br>
&gt;&gt;&gt;&gt; (content ...)<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; The problem that surfaces in a recursive-processing context is that the<br>
&gt;&gt;&gt;&gt; list<br>
&gt;&gt;&gt;&gt; of content might have the same form as an attribute expression, e.g.,<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; ((field-1 &quot;value-1&quot;) (field-2 &quot;value-2&quot;))<br>
&gt;&gt;&gt;&gt; ((p &quot;some text&quot;) (p &quot;some more text&quot;))<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Is there a test I could use to reliably disambiguate between these two<br>
&gt;&gt;&gt;&gt; cases, short of creating a new struct for x-expressions? Seems like I&#39;m<br>
&gt;&gt;&gt;&gt; overlooking some middle ground.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; ____________________<br>
&gt;&gt;&gt;&gt;  Racket Users list:<br>
&gt;&gt;&gt;&gt;  <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; --<br>
&gt;&gt;&gt; Jay McCarthy &lt;<a href="mailto:jay@cs.byu.edu">jay@cs.byu.edu</a>&gt;<br>
&gt;&gt;&gt; Assistant Professor / Brigham Young University<br>
&gt;&gt;&gt; <a href="http://faculty.cs.byu.edu/~jay" target="_blank">http://faculty.cs.byu.edu/~jay</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; &quot;The glory of God is Intelligence&quot; - D&amp;C 93<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; ____________________<br>
&gt;&gt;  Racket Users list:<br>
&gt;&gt;  <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Jay McCarthy &lt;<a href="mailto:jay@cs.byu.edu">jay@cs.byu.edu</a>&gt;<br>
&gt; Assistant Professor / Brigham Young University<br>
&gt; <a href="http://faculty.cs.byu.edu/~jay" target="_blank">http://faculty.cs.byu.edu/~jay</a><br>
&gt;<br>
&gt; &quot;The glory of God is Intelligence&quot; - D&amp;C 93<br>
&gt; ____________________<br>
&gt;  Racket Users list:<br>
&gt;  <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>