Ralf Hemmecke wrote:
> 
> Ooops, what in
> 
> )abbrev domain AAA Aaa
> Aaa: with
>      bar: Integer -> Integer
>    == add
>      (x: Integer := 4; y: Integer := 3)
>      bar(a: Integer): Integer == x + a + z
>      z: Integer := 3 + y
> 
> would be illegal? I just had to replace (as I said) the braces by 
> parentheses, since parens are used to group sequences of commands. (Same 
> as braces in Aldor.)
> Where can I find the specification on which you base your comment?
> 
> The above code does indeed not compile (at least not in fricas). Why?
> 

See subsection 6.16 in Axion book.  This describes interpretar
language, but large part is valid for Spad.  In particular:

 Spad compiler scans your function line-by-line, from top-to-bottom.
 The right-hand side of an assignment is looked at before the left-hand
 side.
 If variable x is referenced before it is assigned a value, it is a
 free (global) variable.
 If x is assigned a value before it is referenced, it is a
 local variable.

Now, the corresponding global variable is undeclared, so Spad
compiler can not find its type.

> 
> Moving the definition of bar to the end, will compile. And calling 
> bar(100) give the expected 110 as output.
> 

Yes, Spad compiles bar without looking at following text.  At the
point of use Spad compiler is not smart enough to deduce type of
z.  And, if such use would declare z, than we would have double
declaration later.

I am not sure if I want to make Spad compiler smarter in such
cases: the snippet above is likely to be an error.  Also, as
a reader I depend strongly on order: if want to know what z
means I need to find where it is defined.  "Define before use"
means that to find definition I need to look only _before_
point of use.

-- 
                              Waldek Hebisch
[EMAIL PROTECTED] 

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
open-axiom-devel mailing list
open-axiom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/open-axiom-devel

Reply via email to