Ralf Hemmecke wrote:
> 
> Dear Waldek,
> 
> On 03/19/2009 12:07 AM, Waldek Hebisch wrote:
> > Ralf Hemmecke wrote:
> >>> --- I'd rather write
> >>> ---   subset?(s, t)   == #s < #t and every?(x +-> member?(x, t), parts s)
> >>> --- but the compiler complains
> >>> -   subset?(s, t)   ==
> >>> -       #s >= #t => false
> >>> -       every?(mem?, parts s) where
> >>> -           mem?(x: S): Boolean == member?(x, t)
> >>> +   subset?(s, t)   == #s <= #t and s = intersect(s,t)
> >> Were you saying that anonymous functions do not work inside a function 
> >> body?
> 
> > Well, above you have _named_ nested function, and such functions
> > do not work (sometimes one gets weird error message, sometimes one
> > silently gets wrong code).  Anonymous functions using #1, etc more
> > or less work (there are bugs, but simple cases should work OK).
> > AFAICS anonymous functions introduced by '+->' are unsupported in
> > Spad.  
> 
> Sorry, I just was looking that the commented line that contained the +->.
> 
> But you made me wonder...
> 
> Indeed
> 
> )abbrev domain AAA Aaa
> Aaa(): with
>    foo: (Integer -> Integer, Integer) -> Integer
>    bar: Integer -> Integer
>   == add
>    foo(f: Integer->Integer, i: Integer): Integer == f i
>    bar(i: Integer): Integer == foo((x: Integer): Integer +-> x+1, i)
> 
> does currently not compile. Wheras entering the last two lines into the 
> interpreter and calling bar(5) seems to work fine.
> 
> > So ATM I prefer to only disable wrong behaviour...
> 
> I'm on your side. But that +-> does not work in the compiler is somewhat 
> surprising for me. Well, I don't use it that often anyway.
>

Actually, one can hack at least some support for '+->' rather
quickly.  Withe the patch below your program, and a version
where the anonymous function uses arguments of bar seem to work.


Index: src/interp/property.lisp
===================================================================
--- src/interp/property.lisp    (revision 548)
+++ src/interp/property.lisp    (working copy)
@@ -411,6 +411,7 @@
   (\@ |compAtSign|)
   (|:| |compColon|)
   (\:\: |compCoerce|)
+  (|+->| |compLambda|)
   (QUOTE |compQuote|)
 
   (|add| |compAdd|)
Index: src/interp/compiler.boot
===================================================================
--- src/interp/compiler.boot    (revision 548)
+++ src/interp/compiler.boot    (working copy)
@@ -143,7 +143,38 @@
   ScanOrPairVec('hasone?,x) where
      hasone? x == MEMQ(x,$formalMapVariables)
 
+argsToSig(args) ==
+    args is [":", v, t] => [[v], [t]]
+    sig1 := []
+    arg1 := []
+    bad := false
+    for arg in args repeat
+        arg is [":", v, t] =>
+             sig1 := [t, :sig1]
+             arg1 := [v, :arg1]
+        bad := true
+    bad => [nil, nil]
+    [REVERSE(arg1), REVERSE(sig1)]
+
+compLambda(x is ["+->", vl, body], m, e) ==
+    -- SAY(["compLambda", x, m])
+    vl is [":", args, target] =>
+        args := 
+             args is ["Tuple", :a1] => a1
+             args
+        LISTP(args) =>
+             [arg1, sig1] := argsToSig(args)
+             sig1 =>
+                 ress := compAtSign(["@", ["+->", arg1, body],
+                                  ["Mapping", target, :sig1]], m, e)
+                 -- SAY(["compLambda returning:", ress.0, ress.1])
+                 ress
+             stackAndThrow ["compLambda", x]
+        stackAndThrow ["compLambda", x]
+    stackAndThrow ["compLambda", x]
+
 compWithMappingMode(x,m is ["Mapping",m',:sl],oldE) ==
+  -- SAY(["compWithMappingMode", x, m])
   $killOptimizeIfTrue: local:= true
   e:= oldE
   isFunctor x =>
@@ -151,7 +182,21 @@
       (and/[extendsCategoryForm("$",s,mode) for mode in argModeList for s in 
sl]
         ) and extendsCategoryForm("$",target,m') then return [x,m,e]
   if STRINGP x then x:= INTERN x
-  for m in sl for v in (vl:= take(#sl,$FormalMapVariableList)) repeat
+  ress := nil
+  if x is ["+->", vl, nx] then
+      vl is [":", :.] =>
+         ress := compLambda(x,m,oldE)
+         -- In case Boot gets fixed
+         ress
+      vl := 
+         SYMBOLP(vl) => [vl]
+         LISTP(vl) and (and/[SYMBOLP(v) for v in vl])=> vl
+         stackAndThrow ["bad +-> arguments:", vl]
+      x := nx
+  else
+      vl:= take(#sl,$FormalMapVariableList)
+  ress => ress
+  for m in sl for v in vl repeat
     [.,.,e]:= compMakeDeclaration([":",v,m],$EmptyMode,e)
   not null vl and not hasFormalMapVariable(x, vl) => return
     [u,.,.] := comp([x,:vl],m',e) or return nil
@@ -237,6 +282,7 @@
   uu:=
     frees => ['CONS,fname,vec]
     ['LIST,fname]
+  -- SAY(["compWithMappingMode returning", uu, m])
   [uu,m,oldE]
 
 extractCodeAndConstructTriple(u, m, oldE) ==

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