Discussion:
[fricas-devel] how to remove "failed"?
Prof. Dr. Johannes Grabmeier privat
2018-05-26 11:42:44 UTC
Permalink
What is going wrong here:

(1) -> li := [2,4,3,2,5,2,7,2,2,7]

   (1)  [2, 4, 3, 2, 5, 2, 7, 2, 2, 7]
                                                                        
Type: List(PositiveInteger)
(2) -> remove(2,li)

   (2)  [4, 3, 5, 7, 7]
                                                                        
Type: List(PositiveInteger)
(3) -> li10 := [recip(i::IntegerMod 10) for i in 0..9]

   (3)  ["failed", 1, "failed", 7, "failed", "failed", "failed", 3,
"failed", 9]
                                                          Type:
List(Union(IntegerMod(10),"failed"))
(4) -> f : Union(IntegerMod(10),"failed") := "failed"

   (4)  "failed"
                                                                          
Type: Union("failed",...)
(5) -> remove(f, li10)
   There are 3 exposed and 1 unexposed library operations named remove
having 2 argument(s)
      but none was determined to be applicable. Use HyperDoc Browse, or
issue
                                         )display op remove
      to learn more about the available operations. Perhaps
package-calling the operation or
      using coercions on the arguments will allow you to apply the
operation.

   Cannot find a definition or applicable library operation named remove
with argument type(s)

                                               failed
                                List(Union(IntegerMod(10),"failed"))

      Perhaps you should use "@" to indicate the required return type,
or "$" to specify which
      version of the function you need

--
Mit freundlichen Grüßen

Johannes Grabmeier

Prof. Dr. Johannes Grabmeier
Köckstraße 1, D-94469 Deggendorf
Tel. +49-(0)-991-2979584, Tel. +49-(0)-151-681-70756
Tel. +49-(0)-991-3615-141 (d), Fax: +49-(0)-32224-192688
--
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
Ralf Hemmecke
2018-05-26 12:22:10 UTC
Permalink
(5) -> remove(f, li10)$List(Union(IntegerMod(10),"failed"))

(5) [1, 7, 3, 9]
Type:
List(Union(IntegerMod(10),"failed"))

Obviously the interpreter is unable to automatically realise that it
should also look inside the exports of List(Union(IntegerMod(10),"failed")).

Ralf
--
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.
oldk1331
2018-05-26 12:40:06 UTC
Permalink
I think this is an interpreter bug, that it automatically coerces a Union
type Union(xx, "yy") to its subtype "yy". (Interpreter can handle types like
Union(Integer,String) )

You can use the following workaround:

remove(x+->x case "failed", l)

But the result type is still List(Union(IntegerMod(10),"failed")).

Another way is to use filter when creating the list:

T ==> IntegerMod 10
[y::T for i in 0..9 | (y := recip(i::T)) case T]

BTW, I think the "Maybe" approach doesn't have this problem.

It can enable functional ways to solve this problem, for example
in Haskell, it only uses ">>= maybeToList":

Prelude> import Data.Maybe
Prelude Data.Maybe> let l = [Nothing, Just 1, Nothing, Just 7]
l :: Num a => [Maybe a]
Prelude Data.Maybe> l >>= maybeToList
[1,7]
it :: Num b => [b]


On Sat, May 26, 2018 at 7:42 PM, Prof. Dr. Johannes Grabmeier privat
Post by Prof. Dr. Johannes Grabmeier privat
(1) -> li := [2,4,3,2,5,2,7,2,2,7]
(1) [2, 4, 3, 2, 5, 2, 7, 2, 2, 7]
Type: List(PositiveInteger)
(2) -> remove(2,li)
(2) [4, 3, 5, 7, 7]
Type: List(PositiveInteger)
(3) -> li10 := [recip(i::IntegerMod 10) for i in 0..9]
(3) ["failed", 1, "failed", 7, "failed", "failed", "failed", 3,
"failed", 9]
List(Union(IntegerMod(10),"failed"))
(4) -> f : Union(IntegerMod(10),"failed") := "failed"
(4) "failed"
Type: Union("failed",...)
(5) -> remove(f, li10)
There are 3 exposed and 1 unexposed library operations named remove
having 2 argument(s)
but none was determined to be applicable. Use HyperDoc Browse, or
issue
)display op remove
to learn more about the available operations. Perhaps
package-calling the operation or
using coercions on the arguments will allow you to apply the
operation.
Cannot find a definition or applicable library operation named remove
with argument type(s)
failed
List(Union(IntegerMod(10),"failed"))
or "$" to specify which
version of the function you need
--
Mit freundlichen Grüßen
Johannes Grabmeier
Prof. Dr. Johannes Grabmeier
Köckstraße 1, D-94469 Deggendorf
Tel. +49-(0)-991-2979584, Tel. +49-(0)-151-681-70756
Tel. +49-(0)-991-3615-141 (d), Fax: +49-(0)-32224-192688
--
You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.
--
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-05-28 10:13:50 UTC
Permalink
Post by Prof. Dr. Johannes Grabmeier privat
(1) -> li := [2,4,3,2,5,2,7,2,2,7]
(1) [2, 4, 3, 2, 5, 2, 7, 2, 2, 7]
Type: List(PositiveInteger)
(3) -> li10 := [recip(i::IntegerMod 10) for i in 0..9]
(3) ["failed", 1, "failed", 7, "failed", "failed", "failed", "failed", 9]
List(Union(IntegerMod(10),"failed"))
(4) -> f : Union(IntegerMod(10),"failed") := "failed"
(4) "failed"
Type: Union("failed",...)
(5) -> remove(f, li10)
There are 3 exposed and 1 unexposed library operations named remove
having 2 argument(s)
but none was determined to be applicable. Use HyperDoc Browse, or
A bug. Removing a single line in 'i-funsel.boot' fixes it:

Index: src/interp/i-funsel.boot
===================================================================
--- src/interp/i-funsel.boot (revision 2423)
+++ src/interp/i-funsel.boot (working copy)
@@ -166,7 +166,6 @@
selectMms2(op,tar,args1,args2,$Coerce) ==
-- decides whether to find functions from a domain or package
-- or by general modemap evaluation
- or/[STRINGP arg for arg in args1] => NIL
if tar = $EmptyMode then tar := NIL
nargs := #args1
mmS := NIL
--
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...