This page is no longer maintained — Please continue to the home page at www.scala-lang.org

a xml elem problem

3 replies
Caesar You
Joined: 2009-09-07,
User offline. Last seen 42 years 45 weeks ago.

is scala.xml.Elem lack of a way to detect a "ring" in
the tree?
that is, if Elem's last parameter(Node*) includes
itself, that will
causes a infinited recursive.

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: a xml elem problem
That would require full recursion on every child Node, which would be rather expensive. Just don't do it.

2009/12/15 Caesar You <Caesar [dot] Jr [at] hotmail [dot] com>
is scala.xml.Elem lack of a way to detect a "ring" in the tree? that is, if Elem's last parameter(Node*) includes itself, that will causes a infinited recursive.



--
Daniel C. Sobral

I travel to the future all the time.
David Pollak
Joined: 2008-12-16,
User offline. Last seen 42 years 45 weeks ago.
Re: a xml elem problem


2009/12/15 Caesar You <Caesar [dot] Jr [at] hotmail [dot] com>
is scala.xml.Elem lack of a way to detect a "ring" in the tree? that is, if Elem's last parameter(Node*) includes itself, that will causes a infinited recursive.

You need to supply the Node * parameters during the construction of the Elem.  But you won't have the instance of the Elem to put in the Node* list during construction, so I don't see how such a case could ever exist.



--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics
extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: a xml elem problem

On Tue, Dec 15, 2009 at 07:59:16AM -0800, David Pollak wrote:
> You need to supply the Node * parameters during the construction of
> the Elem. But you won't have the instance of the Elem to put in the
> Node* list during construction, so I don't see how such a case could
> ever exist.

scala> object o {
lazy val e1: xml.Elem = xml.Elem(null, "a", null, null, e2)
lazy val e2: xml.Elem = xml.Elem(null, "b", null, null, e1)
}
defined module o

scala> o.e1
java.lang.StackOverflowError
at o$.e1(:4)

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland