|
|
 |
 |
 |
 |
Scheme Programming Language
|
 |
 |
 |
 |
 |
 |
 |
 |
Scheme s-expressions mapping to XML
Hello! I'm interesting in relations beetwen Scheme and XML technologies. Now I do a small research in area "mapping between s-expressions and XML". I know about SXML and it's approach, but SXML is mainly mapping from XML to s-expressions. SXML is well known technology technology for those who is interested in XML and Scheme. But I don't know about anything about mapping from s-expressions to XML. It is obviously, that not each s-expression can be mapped in some XML (for SXPath). Do you know about something approach to map any s-exspression to XML?
On 10 Apr 2007 08:06:42 -0700, "Jenia" <evgeni.geni@gmail.com> wrote: >Do you know about something approach to map any s-exspression to XML?
S-expressions consist of atoms and pairs. Atoms may further be distinguished (booleans, symbols, chars, etc.). So you could represent these as XML elements: <pair> ...car goes here... ...cdr goes here... </pair> and <atom kind="boolean"> ...a representation of the atom's value goes here... </atom> Or, you could represent the different kinds of atoms using different elements: <boolean value="#f"/> <char value="A"/> and so on. An XML document is a tree. If your S-expressions will always be trees, then you can represent them directly: '(1 2 3) might be represented as <pair> <atom kind="proc">quote</atom> <pair> <pair> <atom kind="number">1</atom> <pair> <atom kind="number">2</atom> <pair> <atom kind="number">3</atom> <atom kind="empty-list"/> </pair> </pair> </pair> <atom kind="empty-list"/> </pair> </pair> But if you want to represent fully-general S-expressions, which can encode directed graphs rather than just trees, then you'll have to use some kind of indirect references, such as via XML's ID/IDREF mechanism. (In a sense, the above example is already not a tree, since there are two references to the empty list, which should actually point to the same object.) The following is equivalent to that above, using indirect references for everything: <s-expression root-id="PR0005"> <atoms> <atom kind="proc" id="AT0001">quote</atom> <atom kind="number" id="AT0002">1</atom> <atom kind="number" id="AT0003">2</atom> <atom kind="number" id="AT0004">3</atom> <atom kind="empty-list" id="AT0005"/> </atoms> <pairs> <pair id="PR0001" car-id="AT0004" cdr-id="AT0005"/> <pair id="PR0002" car-id="AT0003" cdr-id="PR0001"/> <pair id="PR0003" car-id="AT0002" cdr-id="PR0002"/> <pair id="PR0004" car-id="PR0003" cdr-id="AT0005"/> <pair id="PR0005" car-id="AT0001" cdr-id="PR0004"/> </pairs> </s-expression> It kind of defeats the readibility of XML, but then again, it's always hard to represent nonlinear structures in a serialized format. Computers don't care, of course. Steve Schafer Fenestra Technologies Corp. http://www.fenestra.com/
On 10 , 20:06, Steve Schafer <s@fenestra.com> wrote:
> On 10 Apr 2007 08:06:42 -0700, "Jenia" <evgeni.geni @gmail.com> wrote: > >Do you know about something approach to map any s-exspression to XML? > S-expressions consist of atoms and pairs. Atoms may further be > distinguished (booleans, symbols, chars, etc.). So you could represent > these as XML elements: > <pair> > ...car goes here... > ...cdr goes here... > </pair> > and > <atom kind="boolean"> > ...a representation of the atom's value goes here... > </atom> > Or, you could represent the different kinds of atoms using different > elements: > <boolean value="#f"/> > <char value="A"/> > and so on. > An XML document is a tree. If your S-expressions will always be trees, > then you can represent them directly: > '(1 2 3) > might be represented as > <pair> > <atom kind="proc">quote</atom> > <pair> > <pair> > <atom kind="number">1</atom> > <pair> > <atom kind="number">2</atom> > <pair> > <atom kind="number">3</atom> > <atom kind="empty-list"/> > </pair> > </pair> > </pair> > <atom kind="empty-list"/> > </pair> > </pair> > But if you want to represent fully-general S-expressions, which can > encode directed graphs rather than just trees, then you'll have to use > some kind of indirect references, such as via XML's ID/IDREF mechanism. > (In a sense, the above example is already not a tree, since there are > two references to the empty list, which should actually point to the > same object.) > The following is equivalent to that above, using indirect references for > everything: > <s-expression root-id="PR0005"> > <atoms> > <atom kind="proc" id="AT0001">quote</atom> > <atom kind="number" id="AT0002">1</atom> > <atom kind="number" id="AT0003">2</atom> > <atom kind="number" id="AT0004">3</atom> > <atom kind="empty-list" id="AT0005"/> > </atoms> > <pairs> > <pair id="PR0001" car-id="AT0004" cdr-id="AT0005"/> > <pair id="PR0002" car-id="AT0003" cdr-id="PR0001"/> > <pair id="PR0003" car-id="AT0002" cdr-id="PR0002"/> > <pair id="PR0004" car-id="PR0003" cdr-id="AT0005"/> > <pair id="PR0005" car-id="AT0001" cdr-id="PR0004"/> > </pairs> > </s-expression> > It kind of defeats the readibility of XML, but then again, it's always > hard to represent nonlinear structures in a serialized format. Computers > don't care, of course. > Steve Schafer > Fenestra Technologies Corp.http://www.fenestra.com/
On 10 , 20:06, Steve Schafer <s@fenestra.com> wrote:
> On 10 Apr 2007 08:06:42 -0700, "Jenia" <evgeni.geni @gmail.com> wrote: > >Do you know about something approach to map any s-exspression to XML? > S-expressions consist of atoms and pairs. Atoms may further be > distinguished (booleans, symbols, chars, etc.). So you could represent > these as XML elements: > <pair> > ...car goes here... > ...cdr goes here... > </pair> > and > <atom kind="boolean"> > ...a representation of the atom's value goes here... > </atom> > Or, you could represent the different kinds of atoms using different > elements: > <boolean value="#f"/> > <char value="A"/> > and so on. > An XML document is a tree. If your S-expressions will always be trees, > then you can represent them directly: > '(1 2 3) > might be represented as > <pair> > <atom kind="proc">quote</atom> > <pair> > <pair> > <atom kind="number">1</atom> > <pair> > <atom kind="number">2</atom> > <pair> > <atom kind="number">3</atom> > <atom kind="empty-list"/> > </pair> > </pair> > </pair> > <atom kind="empty-list"/> > </pair> > </pair> > But if you want to represent fully-general S-expressions, which can > encode directed graphs rather than just trees, then you'll have to use > some kind of indirect references, such as via XML's ID/IDREF mechanism. > (In a sense, the above example is already not a tree, since there are > two references to the empty list, which should actually point to the > same object.) > The following is equivalent to that above, using indirect references for > everything: > <s-expression root-id="PR0005"> > <atoms> > <atom kind="proc" id="AT0001">quote</atom> > <atom kind="number" id="AT0002">1</atom> > <atom kind="number" id="AT0003">2</atom> > <atom kind="number" id="AT0004">3</atom> > <atom kind="empty-list" id="AT0005"/> > </atoms> > <pairs> > <pair id="PR0001" car-id="AT0004" cdr-id="AT0005"/> > <pair id="PR0002" car-id="AT0003" cdr-id="PR0001"/> > <pair id="PR0003" car-id="AT0002" cdr-id="PR0002"/> > <pair id="PR0004" car-id="PR0003" cdr-id="AT0005"/> > <pair id="PR0005" car-id="AT0001" cdr-id="PR0004"/> > </pairs> > </s-expression> > It kind of defeats the readibility of XML, but then again, it's always > hard to represent nonlinear structures in a serialized format. Computers > don't care, of course. > Steve Schafer > Fenestra Technologies Corp.http://www.fenestra.com/
I see I need to explain why I need some mapping from s-expressions to XML. If I needed to serialize s-exprs to XML I would use mappinl like you have presented. But I need something another. I want to navigate over s-exprs. via XPath. I have some framework that could provide possibility to navigate other random tree if it has mapping to XML. So I need to have mapping from s-exprs. to navigate over it's tree structure. I'm going to use it in compiler optimizator which is written in Scheme and works with scheme s-exprs. I would like to have mapping which maps (a (b)) to something like that: <a><b/></a>
On 10 ???, 20:56, "Jenia" <evgeni.geni@gmail.com> wrote:
> On 10 , 20:06, Steve Schafer <s @fenestra.com> wrote: > > On 10 Apr 2007 08:06:42 -0700, "Jenia" <evgeni.geni@gmail.com> wrote: > > >Do you know about something approach to map any s-exspression to XML? > > S-expressions consist of atoms and pairs. Atoms may further be > > distinguished (booleans, symbols, chars, etc.). So you could represent > > these as XML elements: > > <pair> > > ...car goes here... > > ...cdr goes here... > > </pair> > > and > > <atom kind="boolean"> > > ...a representation of the atom's value goes here... > > </atom> > > Or, you could represent the different kinds of atoms using different > > elements: > > <boolean value="#f"/> > > <char value="A"/> > > and so on. > > An XML document is a tree. If your S-expressions will always be trees, > > then you can represent them directly: > > '(1 2 3) > > might be represented as > > <pair> > > <atom kind="proc">quote</atom> > > <pair> > > <pair> > > <atom kind="number">1</atom> > > <pair> > > <atom kind="number">2</atom> > > <pair> > > <atom kind="number">3</atom> > > <atom kind="empty-list"/> > > </pair> > > </pair> > > </pair> > > <atom kind="empty-list"/> > > </pair> > > </pair> > > But if you want to represent fully-general S-expressions, which can > > encode directed graphs rather than just trees, then you'll have to use > > some kind of indirect references, such as via XML's ID/IDREF mechanism. > > (In a sense, the above example is already not a tree, since there are > > two references to the empty list, which should actually point to the > > same object.) > > The following is equivalent to that above, using indirect references for > > everything: > > <s-expression root-id="PR0005"> > > <atoms> > > <atom kind="proc" id="AT0001">quote</atom> > > <atom kind="number" id="AT0002">1</atom> > > <atom kind="number" id="AT0003">2</atom> > > <atom kind="number" id="AT0004">3</atom> > > <atom kind="empty-list" id="AT0005"/> > > </atoms> > > <pairs> > > <pair id="PR0001" car-id="AT0004" cdr-id="AT0005"/> > > <pair id="PR0002" car-id="AT0003" cdr-id="PR0001"/> > > <pair id="PR0003" car-id="AT0002" cdr-id="PR0002"/> > > <pair id="PR0004" car-id="PR0003" cdr-id="AT0005"/> > > <pair id="PR0005" car-id="AT0001" cdr-id="PR0004"/> > > </pairs> > > </s-expression> > > It kind of defeats the readibility of XML, but then again, it's always > > hard to represent nonlinear structures in a serialized format. Computers > > don't care, of course. > > Steve Schafer > > Fenestra Technologies Corp.http://www.fenestra.com/
I see I need to explain why I need some mapping from s-expressions to XML. If I needed to serialize s-exprs to XML I would use mappinl like you have presented. But I need something another. I want to navigate over s-exprs. via XPath. I have some framework that could provide possibility to navigate other random tree if it has mapping to XML. So I need to have mapping from s-exprs. to navigate over it's tree structure. I'm going to use it in compiler optimizator which is written in Scheme and works with scheme s-exprs. I would like to have mapping which maps (a (b)) to something like that: <a><b/></a>
Steve Schafer <s @fenestra.com> writes: > An XML document is a tree. If your S-expressions will always be trees, > then you can represent them directly: > '(1 2 3) > might be represented as > <pair> > <atom kind="proc">quote</atom> > <pair> > <pair> > <atom kind="number">1</atom> > <pair> > <atom kind="number">2</atom> > <pair> > <atom kind="number">3</atom> > <atom kind="empty-list"/> > </pair> > </pair> > </pair> > <atom kind="empty-list"/> > </pair> > </pair>
And right there you see clearly why XML representations of scheme are...well...retarded.
> <s-expression root-id="PR0005"> > <atoms> > <atom kind="proc" id="AT0001">quote</atom> > <atom kind="number" id="AT0002">1</atom> > <atom kind="number" id="AT0003">2</atom> > <atom kind="number" id="AT0004">3</atom> > <atom kind="empty-list" id="AT0005"/> > </atoms> > <pairs> > <pair id="PR0001" car-id="AT0004" cdr-id="AT0005"/> > <pair id="PR0002" car-id="AT0003" cdr-id="PR0001"/> > <pair id="PR0003" car-id="AT0002" cdr-id="PR0002"/> > <pair id="PR0004" car-id="PR0003" cdr-id="AT0005"/> > <pair id="PR0005" car-id="AT0001" cdr-id="PR0004"/> > </pairs> > </s-expression>
Jesus. The best xml representation of scheme that I know of is scheme itself, e.g. <my-expression>(1 2 3)</my-expression> or when you have "funny" characters: <my-expression><![CDATA['(1 2 3)]]></my-expression> or even: <my-expression>'(1 2 3)</my-expression> Think about it: scheme is a standard language with a standard representation. There are a million scheme parsers. There is no reason to code up an XML translater when all that is needed is to run a string through a parser. The XML format is not usefully readable, meaning its only good for machine processing, and such machine processing is unnecessarily complicated given the presence of simple scheme parsers that could have been used instead. -- Cheers, The Rhythm is around me, The Rhythm has control. Ray Blaak The Rhythm is inside me, rAYbl@STRIPCAPStelus.net The Rhythm has my soul.
Hello, On Apr 10, 9:05 pm, "Jenia" <evgeni.geni@gmail.com> wrote: > On 10 , 20:06, Steve Schafer <s @fenestra.com> wrote: ... > I see I need to explain why I need some mapping from s-expressions to > XML. If I needed to serialize s-exprs to XML I would use mappinl like > you have presented. But I need something another. I want to navigate > over s-exprs. via XPath. I have some framework that could provide > possibility to navigate other random tree if it has mapping to XML. So > I need to have mapping from s-exprs. to navigate over it's tree > structure.
You can do it with the proposed mapping. (Thanks, Steve!) For example, to find all lists starting with the symbol "xxx", you can say: //pair[item[.='xxx']] But I'm sure it's not convenient. > I'm going to use it in compiler optimizator which is > written in Scheme and works with scheme s-exprs. > I would like to have mapping which maps (a (b)) to something like > that: <a><b/></a>
So, you are looking not for a mapping only, but for some useful human- friendly mapping. Good luck with it. -- Oleg Parashchenko olpa@ http://uucode.com/ http://uucode.com/blog/ Generative Programming, XML, TeX, Scheme http://tohtml.com/ Online syntax highlighting
|
 |
 |
 |
 |
|