Compile error over var name....

12 views
Skip to first unread message

Sid Andal

unread,
Dec 8, 2025, 11:13:49 AM (3 days ago) Dec 8
to FriCAS - computer algebra system
The following program runs fine:


xxxx.input:

F := PF 5

(B1, B2, B3) : Vector F

SetVecs() ==
   free B1, B2, B3
   B1 := [1, 2, 3]
   B2 := [2, 3, 1]
   B3 := [3, 1, 2]
   output("")

GetMatx() ==
   free B1, B2, B3
   X : Matrix F
   X := matrix [B1, B2, B3]
   (output("X:", X); output(""))
   (output("Rank:", rank(X)); output(""))

SetVecs()
GetMatx()


(1) -> )r xxxx
F := PF 5


   (1)  PrimeField(5)

(B1, B2, B3) : Vector F


SetVecs() ==
   free B1, B2, B3
   B1 := [1, 2, 3]
   B2 := [2, 3, 1]
   B3 := [3, 1, 2]
   output("")


GetMatx() ==
   free B1, B2, B3
   X : Matrix F
   X := matrix [B1, B2, B3]
   (output("X:", X); output(""))
   (output("Rank:", rank(X)); output(""))


SetVecs()

   Compiling function SetVecs with type () -> Void

GetMatx()

   Compiling function GetMatx with type () -> Void
      ┌1  2  3┐
      │           │
   X: |  2  3  1│
      │           │
      └3  1  2┘

   Rank: 3


However, the same program fails when var X is replaced with T
in GetMatx():


tttt.input:

F := PF 5

(B1, B2, B3) : Vector F

SetVecs() ==
   free B1, B2, B3
   B1 := [1, 2, 3]
   B2 := [2, 3, 1]
   B3 := [3, 1, 2]
   output("")

GetMatx() ==
   free B1, B2, B3
   T : Matrix F
   T := matrix [B1, B2, B3]
   (output("T:", T); output(""))
   (output("Rank:", rank(T)); output(""))

SetVecs()
GetMatx()


With following errors:


(1) -> )r tttt
F := PF 5


   (1)  PrimeField(5)

(B1, B2, B3) : Vector F


SetVecs() ==
   free B1, B2, B3
   B1 := [1, 2, 3]
   B2 := [2, 3, 1]
   B3 := [3, 1, 2]
   output("")


GetMatx() ==
   free B1, B2, B3
   T : Matrix F
   T := matrix [B1, B2, B3]
   (output("T:", T); output(""))
   (output("Rank:", rank(T)); output(""))


SetVecs()

   Compiling function SetVecs with type () -> Void

GetMatx()

   Compiling function GetMatx with type () -> Void
; in: SB-INT:NAMED-LAMBDA |*0;GetMatx;1;frame1|
;     (BOOT::SPROG ((T NIL))
;                  (PROGN
;                   (BOOT::LETT T 'BOOT::UNINITIALIZED_VARIABLE BOOT::|GetMatx|)
;                   (PROGN
;                    (BOOT::|voidValue|)
;                    (BOOT::LETT T (BOOT::SPADCALL # #) BOOT::|GetMatx|)
;                    (PROGN (BOOT::SPADCALL "T:" # #) (BOOT::SPADCALL "" #))
;                    (PROGN (BOOT::SPADCALL "Rank:" # #) (BOOT::SPADCALL "" #)))))
; --> BLOCK
; ==>
;   (LET (T)
;     (PROGN
;      (BOOT::LETT T 'BOOT::UNINITIALIZED_VARIABLE BOOT::|GetMatx|)
;      (PROGN
;       (BOOT::|voidValue|)
;       (BOOT::LETT T (BOOT::SPADCALL # #) BOOT::|GetMatx|)
;       (PROGN (BOOT::SPADCALL "T:" # #) (BOOT::SPADCALL "" #))
;       (PROGN (BOOT::SPADCALL "Rank:" # #) (BOOT::SPADCALL "" #)))))
;
; caught ERROR:
;   COMMON-LISP:T names a defined constant, and cannot be used in LET.
;
; compilation unit finished
;   caught 1 ERROR condition

   >> System error:
   Execution of a form compiled with errors.
Form:
  (LET (T)
  (PROGN
   (LETT T 'UNINITIALIZED_VARIABLE |GetMatx|)
   (PROGN
    (|voidValue|)
    (LETT T
          (SPADCALL (|coerceOrCroak| # '# '|GetMatx|)
                    (QREFELT |*0;GetMatx;1;frame1;MV| 0))
          |GetMatx|)
    (PROGN
     (SPADCALL "T:" (SPADCALL T #) (QREFELT |*0;GetMatx;1;frame1;MV| 2))
     (SPADCALL "" (QREFELT |*0;GetMatx;1;frame1;MV| 3)))
    (PROGN
     (SPADCALL "Rank:" (SPADCALL # #) (QREFELT |*0;GetMatx;1;frame1;MV| 2))
     (SPADCALL "" (QREFELT |*0;GetMatx;1;frame1;MV| 3))))))
Compile-time error:
  COMMON-LISP:T names a defined constant, and cannot be used in LET.

   Continuing to read the file...


That seems a little strange....

Thanks,
Sid

Ralf Hemmecke

unread,
Dec 8, 2025, 11:54:48 AM (3 days ago) Dec 8
to fricas...@googlegroups.com
> GetMatx() ==
> free B1, B2, B3
> T : Matrix F
> T := matrix [B1, B2, B3]
> (output("T:", T); output(""))
> (output("Rank:", rank(T)); output(""))
Compile-time error:
COMMON-LISP:T names a defined constant, and cannot be used in LET.

> That seems a little strange....

Indeed.

Obvooiously, the interpreter does not properly choos a new name for T.
It cannot map it directly to T in lisp, since in Lisp it simply
represents the true value and not a variable.

That's certainly a bug, but why do you make your input so complicated?
The following also works (even with T as variable).

F := PF 5
T: Matrix F := matrix([_
[1, 2, 3],_
[2, 3, 1],_
[3, 1, 2]]);

output("T:", T); output(""); output("Rank:", rank(T))

Raf

Sid Andal

unread,
Dec 9, 2025, 1:38:19 PM (2 days ago) Dec 9
to FriCAS - computer algebra system
This was part of a larger program and a lot of bits and pieaces had to be removed
and simplified in order to pin down the error.

However, instead of a local var, if T is declared as a global var it runs ok again:


TT.input:


F := PF 5

T : Matrix F

(B1, B2, B3) : Vector F

SetVecs() ==
   free B1, B2, B3

   B1 := [1, 2, 3]
   B2 := [2, 3, 1]
   B3 := [3, 1, 2]
   output("")

GetMatx() ==
   free B1, B2, B3, T

   T := matrix [B1, B2, B3]
   (output("T:", T); output(""))
   (output("Rank:", rank(T)); output(""))

SetVecs()
GetMatx()



(1) -> )r TT

F := PF 5


   (1)  PrimeField(5)

T : Matrix F



(B1, B2, B3) : Vector F


SetVecs() ==
   free B1, B2, B3

   B1 := [1, 2, 3]
   B2 := [2, 3, 1]
   B3 := [3, 1, 2]
   output("")


GetMatx() ==
   free B1, B2, B3, T

   T := matrix [B1, B2, B3]
   (output("T:", T); output(""))
   (output("Rank:", rank(T)); output(""))


SetVecs()

   Compiling function SetVecs with type () -> Void

GetMatx()

   Compiling function GetMatx with type () -> Void
      ┌1  2  3┐
      │           │
   T: | 2  3  1 │

      │           │
      └3  1  2┘

   Rank: 3

(8) ->


It seems the compiler only has issues with the local declaration of T.

Sid

Ralf Hemmecke

unread,
Dec 9, 2025, 2:00:00 PM (2 days ago) Dec 9
to fricas...@googlegroups.com
I still don't understand this...

> (B1, B2, B3) : Vector F

> SetVecs() ==
> free B1, B2, B3
> B1 := [1, 2, 3]
> B2 := [2, 3, 1]
> B3 := [3, 1, 2]
> output("")

Why not defining a macro like this ...

SetVecs(B1,B2,B3) =>
B1 := [1, 2, 3]
B2 := [2, 3, 1]
B3 := [3, 1, 2]

It's a bit unclear to me, why you add output("") at the end of your
function. You certainly know that a semicolon after an expresssion
suppresses its output.

Ralf

Sid Andal

unread,
Dec 10, 2025, 8:58:56 AM (yesterday) Dec 10
to FriCAS - computer algebra system
The function output() doesn't seem to interpret the escape sequences, e.g. "\n". So,
the only way to add a blank line is to add output("") at the end of each function to
separate its outputs from other functions for better readability.
Reply all
Reply to author
Forward
0 new messages