> > --000000000000eac038057ab2cbd5 > Content-Type: text/plain; charset="UTF-8" > > I try to make the meaning of 'children' accurate and consistent: > return value of 'children' should not contain empty aggregate.
Yes, I agree. However, it seems that you change code so that 'children' on empty aggregate returns empty list instead of error. ATM I tend to think that calling 'children' on empty aggregate is an error -- do you have any use case when we want empty list instead of error? > > diff --git a/ChangeLog b/ChangeLog > index cb3e6139..bd671a6e 100644 > --- a/ChangeLog > +++ b/ChangeLog > @@ -1,3 +1,8 @@ > +2018-11-15 Qian Yun <[email protected]> > + > + * src/algebra/aggcat.spad, src/algebra/stream.spad, > + src/algebra/tree.spad: fix 'children' in List, Stream and Tree > + > 2018-11-14 Qian Yun <[email protected]> > > * src/algebra/aggcat.spad: fix 'children' in BRAGG > diff --git a/src/algebra/aggcat.spad b/src/algebra/aggcat.spad > index e16526d6..f7cf5ecb 100644 > --- a/src/algebra/aggcat.spad > +++ b/src/algebra/aggcat.spad > @@ -1054,13 +1054,14 @@ > ++ a directed graph containing values of type S. > ++ Recursively, a recursive aggregate is either empty or a {\em node} > ++ consisting of a \spadfun{value} from S and 0 or more \spadfun{children} > -++ which are recursive aggregates. > +++ which are also nodes. > ++ A node with no children is called a \spadfun{leaf} node. > ++ A recursive aggregate may be cyclic for which some operations as noted > ++ may go into an infinite loop. > RecursiveAggregate(S : Type) : Category == HomogeneousAggregate(S) with > children : % -> List % > ++ children(u) returns a list of the children of aggregate u. > + ++ Returns \spad{empty()} if u is empty aggregate. > -- should be % -> %* and also needs children: % -> Iterator(S, S) > nodes : % -> List % > ++ nodes(u) returns a list of all of the nodes of aggregate u. > @@ -1299,7 +1300,6 @@ > ++ A node with one children models a non-empty list, with the > ++ \spadfun{value} of the list designating the head, or > \spadfun{first}, of the > ++ list, and the child designating the tail, or \spadfun{rest}, of the > list. > -++ A node with no child then designates the empty list. > ++ Since these aggregates are recursive aggregates, they may be cyclic. > UnaryRecursiveAggregate(S : Type) : Category == RecursiveAggregate S with > concat : (%, %) -> % > @@ -1421,7 +1421,7 @@ > reverse! l > > children x == > - empty? x => empty() > + empty? x or empty? rest x => empty() > [rest x] > > leaf? x == > diff --git a/src/algebra/stream.spad b/src/algebra/stream.spad > index 33cffce1..c21cc581 100644 > --- a/src/algebra/stream.spad > +++ b/src/algebra/stream.spad > @@ -325,7 +325,7 @@ > x = rst y > > children x == > - empty? x => error "children: no children" > + empty? x or empty? rst x => empty() > [rst x] > > distance(x, z) == > diff --git a/src/algebra/tree.spad b/src/algebra/tree.spad > index c58aae21..213b20c1 100644 > --- a/src/algebra/tree.spad > +++ b/src/algebra/tree.spad > @@ -42,7 +42,7 @@ > empty() == ["empty"] > > children t == > - t case empty => error "cannot take the children of an empty tree" > + t case empty => empty() > (t.node.args)@List(%) > setchildren!(t, lt) == > t case empty => error "cannot set children of an empty tree" > diff --git a/src/input/bugs2018.input b/src/input/bugs2018.input > index e08adf3d..adfb8054 100644 > --- a/src/input/bugs2018.input > +++ b/src/input/bugs2018.input > @@ -199,4 +199,12 @@ > > testTrue("empty? children binarySearchTree [1]") > > +testcase "'children' in List, Stream and Tree" > + > +testTrue("empty? children [1]") > + > +testTrue("empty? children([1]@Stream Integer)") > + > +testTrue("empty? children(empty()$Tree Integer)") > + > statistics() > > -- > You received this message because you are subscribed to the Google Groups > "FriCAS - computer algebra system" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/fricas-devel. > For more options, visit https://groups.google.com/d/optout. > > --000000000000eac038057ab2cbd5 > Content-Type: text/html; charset="UTF-8" > Content-Transfer-Encoding: quoted-printable > > <div dir=3D"auto">I try to make the meaning of 'children' accurate = > and consistent:<br> > return value of 'children' should not contain empty aggregate.<br> > <br> > <br> > diff --git a/ChangeLog b/ChangeLog<br> > index cb3e6139..bd671a6e 100644<br> > --- a/ChangeLog<br> > +++ b/ChangeLog<br> > @@ -1,3 +1,8 @@<br> > +2018-11-15=C2=A0 Qian Yun=C2=A0 <<a href=3D"mailto:[email protected]" = > target=3D"_blank" rel=3D"noreferrer">[email protected]</a>><br> > +<br> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0* src/algebra/aggcat.spad, src/algebra/stream.s= > pad,<br> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0src/algebra/tree.spad: fix 'children' i= > n List, Stream and Tree<br> > +<br> > =C2=A0 2018-11-14=C2=A0 Qian Yun=C2=A0 <<a href=3D"mailto:oldk1331@gmail= > .com" target=3D"_blank" rel=3D"noreferrer">[email protected]</a>><br> > <br> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* src/algebra/aggcat.spad: fix 'child= > ren' in BRAGG<br> > diff --git a/src/algebra/aggcat.spad b/src/algebra/aggcat.spad<br> > index e16526d6..f7cf5ecb 100644<br> > --- a/src/algebra/aggcat.spad<br> > +++ b/src/algebra/aggcat.spad<br> > @@ -1054,13 +1054,14 @@<br> > =C2=A0 ++ a directed graph containing values of type S.<br> > =C2=A0 ++ Recursively, a recursive aggregate is either empty or a {\em node= > }<br> > =C2=A0 ++ consisting of a \spadfun{value} from S and 0 or more \spadfun{chi= > ldren}<br> > -++ which are recursive aggregates.<br> > +++ which are also nodes.<br> > =C2=A0 ++ A node with no children is called a \spadfun{leaf} node.<br> > =C2=A0 ++ A recursive aggregate may be cyclic for which some operations as = > noted<br> > =C2=A0 ++ may go into an infinite loop.<br> > =C2=A0 RecursiveAggregate(S : Type) : Category =3D=3D HomogeneousAggregate(= > S) with<br> > =C2=A0 =C2=A0 =C2=A0children : % -> List %<br> > =C2=A0 =C2=A0 =C2=A0 =C2=A0++ children(u) returns a list of the children of= > aggregate u.<br> > +=C2=A0 =C2=A0 =C2=A0++ Returns \spad{empty()} if u is empty aggregate.<br> > =C2=A0 =C2=A0 =C2=A0-- should be % -> %* and also needs children: % ->= > ; Iterator(S, S)<br> > =C2=A0 =C2=A0 =C2=A0nodes : % -> List %<br> > =C2=A0 =C2=A0 =C2=A0 =C2=A0++ nodes(u) returns a list of all of the nodes o= > f aggregate u.<br> > @@ -1299,7 +1300,6 @@<br> > =C2=A0 ++ A node with one children models a non-empty list, with the<br> > =C2=A0 ++ \spadfun{value} of the list designating the head, or <br> > \spadfun{first}, of the<br> > =C2=A0 ++ list, and the child designating the tail, or \spadfun{rest}, of t= > he <br> > list.<br> > -++ A node with no child then designates the empty list.<br> > =C2=A0 ++ Since these aggregates are recursive aggregates, they may be cycl= > ic.<br> > =C2=A0 UnaryRecursiveAggregate(S : Type) : Category =3D=3D RecursiveAggrega= > te S with<br> > =C2=A0 =C2=A0 =C2=A0concat : (%, %) -> %<br> > @@ -1421,7 +1421,7 @@<br> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 reverse! l<br> > <br> > =C2=A0 =C2=A0 children x =3D=3D<br> > -=C2=A0 =C2=A0 =C2=A0 empty? x =3D> empty()<br> > +=C2=A0 =C2=A0 =C2=A0 empty? x or empty? rest x =3D> empty()<br> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 [rest x]<br> > <br> > =C2=A0 =C2=A0 leaf? x =3D=3D<br> > diff --git a/src/algebra/stream.spad b/src/algebra/stream.spad<br> > index 33cffce1..c21cc581 100644<br> > --- a/src/algebra/stream.spad<br> > +++ b/src/algebra/stream.spad<br> > @@ -325,7 +325,7 @@<br> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 x =3D rst y<br> > <br> > =C2=A0 =C2=A0 children x =3D=3D<br> > -=C2=A0 =C2=A0 empty? x =3D> error "children: no children"<br> > +=C2=A0 =C2=A0 empty? x or empty? rst x =3D> empty()<br> > =C2=A0 =C2=A0 =C2=A0 [rst x]<br> > <br> > =C2=A0 =C2=A0 distance(x, z) =3D=3D<br> > diff --git a/src/algebra/tree.spad b/src/algebra/tree.spad<br> > index c58aae21..213b20c1 100644<br> > --- a/src/algebra/tree.spad<br> > +++ b/src/algebra/tree.spad<br> > @@ -42,7 +42,7 @@<br> > =C2=A0 =C2=A0 =C2=A0 empty()=C2=A0 =3D=3D ["empty"]<br> > <br> > =C2=A0 =C2=A0 =C2=A0 children t =3D=3D<br> > -=C2=A0 =C2=A0 =C2=A0 t case empty =3D> error "cannot take the chil= > dren of an empty tree"<br> > +=C2=A0 =C2=A0 =C2=A0 t case empty =3D> empty()<br> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 (t.node.args)@List(%)<br> > =C2=A0 =C2=A0 =C2=A0 setchildren!(t, lt) =3D=3D<br> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 t case empty =3D> error "cannot set chi= > ldren of an empty tree"<br> > diff --git a/src/input/bugs2018.input b/src/input/bugs2018.input<br> > index e08adf3d..adfb8054 100644<br> > --- a/src/input/bugs2018.input<br> > +++ b/src/input/bugs2018.input<br> > @@ -199,4 +199,12 @@<br> > <br> > =C2=A0 testTrue("empty? children binarySearchTree [1]")<br> > <br> > +testcase "'children' in List, Stream and Tree"<br> > +<br> > +testTrue("empty? children [1]")<br> > +<br> > +testTrue("empty? children([1]@Stream Integer)")<br> > +<br> > +testTrue("empty? children(empty()$Tree Integer)")<br> > +<br> > =C2=A0 statistics()<br></div> > > <p></p> > > -- <br /> > You received this message because you are subscribed to the Google Groups &= > quot;FriCAS - computer algebra system" group.<br /> > To unsubscribe from this group and stop receiving emails from it, send an e= > mail to <a href=3D"mailto:[email protected]">fricas= > [email protected]</a>.<br /> > To post to this group, send email to <a href=3D"mailto:fricas-devel@googleg= > roups.com">[email protected]</a>.<br /> > Visit this group at <a href=3D"https://groups.google.com/group/fricas-devel= > ">https://groups.google.com/group/fricas-devel</a>.<br /> > For more options, visit <a href=3D"https://groups.google.com/d/optout">http= > s://groups.google.com/d/optout</a>.<br /> > > --000000000000eac038057ab2cbd5-- > -- Waldek Hebisch -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/fricas-devel. For more options, visit https://groups.google.com/d/optout.
