Hi!

I'm playing with a weird anonymous function (motivation below)
and I'm stumbling on a weird error, like if information
on a local variable y is exiting from an anonymous function,
only in a specific case.

I'm reporting this to you in case it was a bug.

(1) -> (():Void +-> {free x; x:=1; local y; y:= 1; output( sin(x+y)); 
output("ciao"); ()})() -- no problem
   sin(2)
   ciao
                                                                   Type: Void
(2) -> (():Void +-> {free x; x:=1; local y; y:= 1; output( sin(x+y)); 
output("ciao"); ()})(); output(x+1) -- no problem
   sin(2)
   ciao
   2
                                                                   Type: Void
(3) -> (():Void +-> {free x; x:=1; local y; y:= 1; output( sin(x+y)); 
output("ciao"); ()})();y --problem
   sin(2)
   ciao
y is declared as being in PositiveInteger but has not been given a
      value.


Why? In the global scope, y should have been valued to a symbol or Variable(y) 
with NO type declaration.

The message is absent if y is on another line:

(4) -> (():Void +-> {free x; x:=1; local y; y:= 1; output( sin(x+y)); 
output("ciao"); ()})()
   sin(2)
   ciao
                                                                   Type: Void
(5) -> y

   (5)  y
                                                            Type: Variable(y)


ric


PS
Motivation for the weird anonymous function above (Thanks for any feedback)

I'm looking for a scoping construct that could keep clean the global environment
from a proliferation of temporary variables in interpreter computations / input 
files.

The body of functions is obviously one solution, but it is slightly boring
to define and immediately execute:

hereIDoThis(globalPars) == {...body with temporary, local variables...}
hereIDoThis(globaPars)

In Aldor the "... where ..." construct is supposed to be another scoping 
construct
but in Spad I have the impression that I can use only in domain declarations.
EG the following give me errors:
(4) -> a where a:=1
  Line   1: a where a:=1
           ........A
  Error  A: syntax error at top level
  Error  A: Improper syntax.
   2 error(s) parsing

(4) -> a where {a:=1}
  Line   1: a where {a:=1}
           ........A
  Error  A: syntax error at top level
  Error  A: Improper syntax.
   2 error(s) parsing

In Mathematica there are the command Block[{x,y,z}, statements] and 
Module[{x,y,z}, statements]
that keep x,y,z "local" (actually in Block x,y,z are global but mask possible 
global values).
All other symbols in the statements have global scope.
It is not optimal to have "global by default" but it is useful to have such 
Block-s.

So, I was trying to implement a block macro that could execute a sequence of 
statements
inside the body of an anonymous function and call it immediately.
Compared to plain functions this would avoid the explicit execution.
Compared to Mathematica Block, Module this would have the advantage
that undeclared variables in RHS of statements are local.

I ended with:

macro block(statements) == (():Void +-> { statements; () })()

... but I had the aforementioned error:

(3) ->  x:=1; y:=1; z:= 1; t:=1; block(free x; local y; x:=2; y:=2; z:=2; t:= 
2; w:=2; output([x,y,z,t])); [x,y,z,t,w]
   [2, 2, 2, 2]
y is declared as being in PositiveInteger but has not been given a
      value.

--
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+unsubscr...@googlegroups.com.
To post to this group, send email to fricas-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to