Alasdair McAndrew wrote:
> 
> I tried to define
> 
> U==>Union(DoubleFloat, Integer)
> 
> and then have the return list r to be of type U:
> 
> r:List U:=...
> 
> Then I thought r could happily include both DF's and integers.  But it
> doesn't work in the way I hoped it would.  Drat.

Well, at low level elements of Union consist of tag and value.
Tag if a small integer identifying which variant is at force.
More precisely, Spad union is interpreted as Lisp pair,
consisting of tag and value:

(9) -> PRETTYPRINT(2::U)$Lisp
(0 . 2.0)

   (9)  ()
                                                            Type: SExpression

The dot above indicates that this is not a list but
a general pair (pairs in lists have rest of list as second
element).  For some reason interpreter decided to treat 2
as a double, so we got first variant (with tag 0).

Having list of such pairs is quite different than list
which mixes integers and doubles:

(10) -> PRETTYPRINT([2::U])$Lisp
((0 . 2.0))

   (10)  ()
                                                            Type: SExpression
(11) -> PRETTYPRINT([2])$Lisp   
(2)

   (11)  ()
                                                            Type: SExpression
(12) -> PRETTYPRINT([2::DoubleFloat])$Lisp
(2.0)

   (12)  ()
                                                            Type: SExpression

-- 
                              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 http://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to