Please, can you explain the following two features?

`unparse' in Spad
*****************
The program

-------------------------------------------- t.input
INT ==> Integer
show(xs : List INT) : String == 
                             oF := xs   :: OutputForm
                             unparse(oF :: InputForm)   
f(xs : List INT) : INT ==  
           empty? xs => 0
           n := first xs
           n < 2  => error concat["f ", show xs, " :  first(arg) < 2."]
           n + 1
--------------------------------------------

works in the interpreter. And its Spad analogue

-------------------------------------------------- t.spad 
INT ==> Integer
)abbrev package FOO Foo
Foo() : with  
        show : List INT -> String
        f    : List INT -> INT
 ==
  add
    show(xs : List INT) : String == 
                                 oF := xs   :: OutputForm
                                 unparse(oF :: InputForm)   
    f(xs : List INT) : INT ==  
           empty? xs => 0
           n := first xs
           n < 2  => error concat["f ", show xs, " :  first(arg) < 2."]
           n + 1
----------------------------------------------------------

does not compile. How to make it work, please?



Error messages
**************
I am looking into  src/algebra/*.spad*  in FriCAS-1.1.5  for the 
examples of forming a message under applying `error'. 
And the examples occur like this: 

   f(l : List Foo) : List Foo == 
                              empty? l => l
                              first(l) = 0 => error "first(l) = 0"

As I think, the error report will be like this:

   Error in the library code:
   first(l) = 0

It does not show in what function and of what package the break has 
happened, and what are the responsible argument values.

What I am missing, please?

In Haskell, I write like this

   f xs = let msg = showString "\nModule Foo,  f " . shows xs . 
                                                     showString "\n:\n"
          in
          if  head xs == 0  then  error $ msg "head xs == 0.\n"
          else
          ...
Here the function  msg :: String -> String  is used in all the error 
calls in the body of  f,  it presents a common prefix for these 
messages. For example,  f [0,3]   breaks with the message

--------------------
  Error ...
Module Foo,  f [0,3]
:
head xs == 0.
--------------------

Respecively, my code of  
             ... => error concat["f ", show xs, " :  first(arg) < 2."]

is an attempt to follow this style in Spad 
(but this `show' does not work).

What are your comments, please?
Thanks,

------
Sergei
[email protected]


-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/fricas-devel?hl=en.

Reply via email to