Difference between revisions of "CoCoA:CoCoA4Language Issues"

From ApCoCoAWiki
(add BigInt vs. Int, ForLoop oddness and F (x+y) vs. F(x+y);)
 
 
(3 intermediate revisions by 2 users not shown)
Line 7: Line 7:
 
==F (x+y); vs. F(x+y);==
 
==F (x+y); vs. F(x+y);==
  
Imagine the follwing situation: You define a function F and also a variable F that contains a polynomial. What should CoCoA do when encountering the two constructs from above?
+
Imagine the following situation: You define a function F and also a variable F that contains a polynomial. What should CoCoA do when encountering the two constructs from above?
  
 
=Problems with the implementation in CoCoA 4.X=
 
=Problems with the implementation in CoCoA 4.X=
 
==Variable in for loops==
 
==Variable in for loops==
Take a look at the folling code:
+
Take a look at the following code:
  
 
  For I:=1 To 4 Do
 
  For I:=1 To 4 Do
Line 19: Line 19:
 
  EndFor;
 
  EndFor;
  
You would expect that the change to the variable I in the body of the for-loop would be permanent, i.e. the number of iterations in the for-loop would be halved by incrementin I by one in each iteration. Alas, the output from CoCoA 4.X results in  
+
You would expect that the change to the variable I in the body of the for-loop would be permanent, i.e. the number of iterations in the for-loop would be halved by incrementing I by one in each iteration. Alas, the output from CoCoA 4.X results in  
  
 
  Before 1 - After: 2
 
  Before 1 - After: 2
Line 42: Line 42:
 
The error returned by CoCoA 4.X in that case is  
 
The error returned by CoCoA 4.X in that case is  
 
  ERROR: Cannot cast to INT (integer too big)
 
  ERROR: Cannot cast to INT (integer too big)
 +
 +
==Size(List) returns length of list==
 +
 +
Size should return the size of an object in bytes. When applied to lists Size returns the length of the list.

Latest revision as of 15:20, 16 October 2007

Introduction

This page lists a number of issues that are either ambiguous or limitations in the language of CoCoA4 itself. As we implement the new CoCoA5Client this page is sure to grow larger.

Problems with ambiguity in the language in CoCoA 4.X

F (x+y); vs. F(x+y);

Imagine the following situation: You define a function F and also a variable F that contains a polynomial. What should CoCoA do when encountering the two constructs from above?

Problems with the implementation in CoCoA 4.X

Variable in for loops

Take a look at the following code:

For I:=1 To 4 Do
  Print "Before ", I;
  I:= I+1;
  Println " - After: ", I;
EndFor;

You would expect that the change to the variable I in the body of the for-loop would be permanent, i.e. the number of iterations in the for-loop would be halved by incrementing I by one in each iteration. Alas, the output from CoCoA 4.X results in

Before 1 - After: 2
Before 2 - After: 3
Before 3 - After: 4
Before 4 - After: 5

This should not happen.

BigInt vs. Int

In some situations in the interpreter of CoCoA 4.X we are limited by the use of integers when parsing parameters, i.e. the range operator ".." will currently fail when feeding the following statement to CoCoA 4.X:

L:= 2^32..2^32+3;

Another place where this happens is inside for-loops, when start or stop value exceed max-int. i.e.

For I:=2^32 To 2^32+3 Do
  PrintLn(I);
EndFor;

The error returned by CoCoA 4.X in that case is

ERROR: Cannot cast to INT (integer too big)

Size(List) returns length of list

Size should return the size of an object in bytes. When applied to lists Size returns the length of the list.