Discussion:
[fricas-devel] [FricasUG] FIXME: sec 2.5.2 pag 96 osolete description & Feature suggestion for Union-s
Riccardo GUIDA
2018-06-28 12:54:12 UTC
Permalink
Hi,

if this is not the correct place for sending FricasUG fix requirements, please excuse me and let me now.

RiCCardo

[FricasUG] FIXME: sec 2.5.2 "Union-s with selectors" pag 96
"Note that case uses the selector name as its right-hand argument. If you accidentally use the branch
type on the right-hand side of case, false will be returned. Now it returns error."


(1) -> U := Union(i:Integer, s:String)

(1) Union(i: Integer,s: String)
Type: Type
(2) -> x:U := "bam"

(2) "bam"
Type: Union(s: String,...)
(3) -> x case Integer
upcase: bad Union form

(3) -> x case String
upcase: bad Union form

(3) -> x case i

(3) false
Type: Boolean
(4) -> x case s

(4) true

The statements above prove that the fricasUG must be fixed.


=== Feature suggestion for Union-s ===

I must say that I would find more natural (and maybe it would have simpler code)
to have the predicates
x case Integer
x case String
as for non-selector Union-s and to use selectors only to get the values
x.i
x.s
with "failed" instead of a coerce error when the inappropriate selector is called: relying on the fact that a coercion might rescue you if the value branch does not correspond to the selector looks somehow hackish.

(5) -> x.i
"bam" of mode Union(i: Integer,s: String) cannot be coerced to mode Integer

(5) -> x.s

(5) "bam"
Type: String
--
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 fricas-devel+***@googlegroups.com.
To post to this group, send email to fricas-***@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.
Riccardo GUIDA
2018-06-28 15:03:30 UTC
Permalink
Sorry, I retract my feature suggestion because Union with selectors are there also in Aldor and with more features that make such selectors more meaningful: i.e. assignment via selector, like u := [num == 3].
RiCCardo
--
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 fricas-devel+***@googlegroups.com.
To post to this group, send email to fricas-***@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.
Waldek Hebisch
2018-06-29 15:56:30 UTC
Permalink
Post by Riccardo GUIDA
Hi,
if this is not the correct place for sending FricasUG fix requirements, please excuse me and let me now.
RiCCardo
[FricasUG] FIXME: sec 2.5.2 "Union-s with selectors" pag 96
"Note that case uses the selector name as its right-hand argument. If you accidentally use the branch
type on the right-hand side of case, false will be returned. Now it returns error."
(1) -> U := Union(i:Integer, s:String)
(1) Union(i: Integer,s: String)
Type: Type
(2) -> x:U := "bam"
(2) "bam"
Type: Union(s: String,...)
(3) -> x case Integer
upcase: bad Union form
(3) -> x case String
upcase: bad Union form
(3) -> x case i
(3) false
Type: Boolean
(4) -> x case s
(4) true
The statements above prove that the fricasUG must be fixed.
Yes, above using type gives an error. I need to check to determine
if error will be always detected. Consider perverse things like

Union(Integer : Float, Float : Integer)

ATM you can create it but there are problem during use. But there
are natural coding examples which can lead to similar things.
More precisely, there are situations when we want to use the
same identifier as union tag and as variable name. But variables
may contain types. Natural solution is to treat identifier as
tag name, ignoring possible meaning as a type. Of course,
behaviour you see is different.
Post by Riccardo GUIDA
=== Feature suggestion for Union-s ===
I must say that I would find more natural (and maybe it would have simpler code)
to have the predicates
x case Integer
x case String
as for non-selector Union-s
That would be quite problematic.
--
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 fricas-devel+***@googlegroups.com.
To post to this group, send email to fricas-***@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.
Loading...