The syntax for declarations which have multiple variables is given on page 142 of the Axiom book. However, using this syntax inside a function results in the compiler failing. The first time an attempt is made to compile a function which uses this syntax, no diagnostic is produced. However, the libraries needed by the function being compiled are not loaded, and the function itself is not executed (or at least it doesn't produce any output). If a second attempt is made to execute the function, a "System error" results. The following session transcript demonstrates the problem. It attempts to execute two functions. The first of these, named "bug", demonstrates the behavior described above. The second function, named "nonbug", is identical to "bug" except that the declaration containing two variables has been replaced by two declarations each containing a single variable. Axiom handles the "nonbug" function correctly, demonstrating that the problem is triggered by a declaration containing multiple variables. The transcript follows: $ axiom AXIOM Computer Algebra System Version: Axiom (April 2006) Timestamp: Wednesday June 21, 2006 at 03:45:56 ----------------------------------------------------------------------------- Issue )copyright to view copyright notices. Issue )summary for a summary of useful system commands. Issue )quit to leave AXIOM and return to shell. ----------------------------------------------------------------------------- (a,b):Integer is incorrect syntax --wyscc, Sat, 08 Sep 2007 14:37:53 -0500 reply I tried:
fricas (1) -> nobug(x) == (local a, Type: Void
fricas nobug(1) fricas Compiling function nobug with type PositiveInteger -> Integer
Type: PositiveInteger?
fricas bug(x) == (local a, Type: Void
fricas bug(1) Also, when I tried this in my Windows version, I got: AXIOM Computer Algebra System Version of Tuesday November 30, 2004 at 21:11:14 ----------------------------------------------------------------------------- Issue )copyright to view copyright notices. Issue )summary for a summary of useful system commands. Issue )quit to leave AXIOM and return to shell. ----------------------------------------------------------------------------- So the older version caught the syntax error on first compile and run. Your example seems to me to be a syntax error that was not caught in the current version on first compile and run (I was not able to find the (a,b):Type is syntactic sugar in the interpreter and a,b:Type does not define type of a correctly (but b is typed correctly; probably the reason to require parenthesis---this requires the interpreter parser to distinguish (a,b) to the left of : from to the right of : ). So this is another inconsistency between interpreter and compiler, or this may be due to an original bug or an unknown difficulty in parsing the comma separator in the interpreter. Alternatively, if the compiler manual says (a,b):Type should be okay, then it is a compiler bug and the workaround is to use a,b:Type .
fricas (a, Type: Void
fricas a:= 11
Type: Polynomial(Integer)
fricas typeOf a
Type: Type
fricas b:= 12
Type: Polynomial(Integer)
fricas a+b
Type: Polynomial(Integer)
fricas c, Type: Tuple(Void)
fricas c:=11
Type: PositiveInteger?
fricas d:=12
Type: Polynomial(Integer)
fricas c+d
Type: Polynomial(Integer)
Why does fricas c, Type: Tuple(Void)
is a tuple, consisting of a symbol `c' and a declaration `d: POLY INT'. However, a declaration has type `Void', and since a Tuple is a homogeneous container, both component must be brought to a common type, which is `Void'. Thus we get a Tuple Void. But, a `Void' is not coercible to OutputForm?, therefore we get the LISP output. Try fricas 2,
Type: Tuple(PositiveInteger?)
I agree with William that the syntax (a,b): Integer is inappropriate.
We should strive for a regular syntax -- otherwise things get confused
including the tools and humans. Syntactically, a comma constructs a tuple
objects, so `a,b' is a tuple of two things. If we want to type it, then
the type should be a tuple so that `(a,b): Tuple Integer' is a
destructural declaration of two things. But `(a,b): Integer' is bound to cause
problem because it appears as if we have a declaration with name `(a,b)'.
My preference would be that we reject the declaration `(a,b): Integer' - which is invalid based on the above explanation. And we also reject `(a,b): Tuple Integer' because, if we do accept it, then we should logically -- for consistency -- accept `(a,b): Tuple Integer := tupleExpression'. But we have, in general, no way to know that the initializer has exactly two components, so we have an invitation for subtle errors. Opinions? |