On 04/28/2014 08:32 AM, jiazhaoconga wrote:
> The reason that 'plus (f,g) == x+->f(x)+g(x)' fails in interpreter may
> have nothing to do with type system, but because of interpreter can
> not handle closure:

You are not totally right, it seems.

(4) -> a(x: Integer):(Integer->Integer) == (y:Integer):Integer +-> y+x
   Function declaration a : Integer -> (Integer -> Integer) has been
      added to workspace.
                                                                   Type:
Void
(5) -> a 4
   Compiling function a with type Integer -> (Integer -> Integer)

   (5)
   theMap
      #<FUNCTION (LAMBDA (#:G663 |envArg|) :IN |*1;a;1;frame1|)
{10048D621B}>
  ,
      655
                                                   Type: (Integer ->
Integer)
(6) -> (a 4) 7

> For example, the 'adder' function:
>   adder x == y +-> y + x
> 
> It totally works in Spad form,

You mean without giving any type?

> but in interpreter:
> 
> (2) -> q := adder 3
>    Compiling function adder with type PositiveInteger ->
>       AnonymousFunction
> 
>    (2)  y +-> y + #1
>                                                       Type: AnonymousFunction
> (3) -> q 4
> 
>    (3)  #1 + 4
>                                                     Type: Polynomial(Integer)
> 
> The '#1' should be the captured value of 'x', thus 3.
> 
> So, interpreter can not handle captured variable, aka closure,
> this is a bug, am I right?

Right. That smells like a bug. The #1 notation for formal parameters has
been removed from FriCAS. Maybe the following makes it more apparent,
what the problem might be.

(7) -> b(x: Any):(Any->Any) == (y:Any):Any +-> y+x
   Function declaration b : Any -> (Any -> Any) has been added to
      workspace.
                                                                   Type:
Void
(9) -> (b 5) 8

   (9)  G665 + 8
                                                    Type:
Polynomial(Integer)

To be honest, I would have liked that the definition of b is rejected,
since the type Any does not export a + function, so y+x is actually not
possible.

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 [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