[Pas2js] array of const
warleyalex
warleyalex at yahoo.com.br
Sat Feb 16 03:39:21 CET 2019
Array of const Tests
***********************************************************
Test I
==============================================
const PId = 3.141592653589793 * 2; // compiler generates possible dead
code
const LETTERS = ['A'..'Z', 'a'..'z']; // it's OK
console.log(PId);
Note:-> the pas2js emits this JS
this.PId = 3.141592653589793 * 2; ---> this is probably a dead code
window.console.log(6.2831853071795862);
==============================================
Test II
==============================================
const
a1 : array [0..2] of String = ('zero', 'one', 'two'); //--> hum it uses
parenteses delimiter, it's OK.
var
a2 : array [0..2] of String;
console.log(a1);
a2 := ['zero', 'one', 'two'];
console.log(a2);
Note: it emits this:
this.a1 = ["zero","one","two"]; // OK initialization
$mod.a2 = ["zero","one","two"];
window.console.log($mod.a1.slice(0)); // slice(0) allows you to return an
array of the existing array you're referencing, a simple
window.console.log($mod.a1) is enough a think;
==============================================
test III
==============================================
const a : array [1..4] of Integer = (11, 22, 33, 44);
console.log(a[1]);
console.log(a[2]);
console.log(a[3]);
console.log(a[4]);
for i:=Low(a) to High(a) do
console.log(a[i]);
11
22
33
44
==============================================
test IV
==============================================
const ac : array [1..4] of Integer = (11, 22, 33, 44);
var aa: array of Integer;
aa := ac;
for i:=Low(aa) to High(aa) do
console.log(aa[i]);
11
22
33
44
==============================================
test V
==============================================
type TEnum = (en1, en2, en3);
const ace : array [TEnum] of String = ('one', 'two', 'three');
const ac2 = ace; ---> project1.lpr(57,15) Error: Constant expression
expected
==============================================
test VI
==============================================
type TEnum = (en1, en2, en3);
const ace : array [TEnum] of String = ('one', 'two', 'three');
//const ac2 = ace;
var j : TEnum;
type TEnum2 = (en1, en2, en3); //----> I think this is a bug,
project1.lpr(61,19) Error: Duplicate identifier "en1" at project1.lpr(54,20)
==============================================
test VII
==============================================
type TEnum = (en1, en2, en3);
const ace : array [TEnum] of String = ('one', 'two', 'three');
//const ac2 = ace;
var j : TEnum;
type TEnum2 = (en01, en02, en03);
type TEnumArray = array [TEnum2] of string;
const acb : TEnumArray = ('one', 'two', 'three');
const ac21 : TEnumArray = acb; //--> it compiles as expected!
var k : TEnum2;
for j in TEnum do
console.log(ace[j]);
//for j in TEnum do
// console.log(ac2[j]);
for k in TEnum2 do
console.log(acb[k]);
//for k in TEnum2 do
// console.log(ac21[k]); //--> does not work for me :(
==============================================
test VIII
==============================================
const
X: array [0..1, 0..2] of Integer = ([1, 2, 3], [4, 5, 6]);
console.log(X[0,0]);
for w := Low(X) to High(X) do
for z := Low(X[w]) to High(X[w]) do // ---> we got "Error: Wrong number
of parameters for array"
console.log(IntToStr(w)+', '+IntToStr(z)+' : '+IntToStr(X[w, z]));
==============================================
test IX
==============================================
type
TDayTable = array[1..12] of Integer;
const
{ True=Leapyear }
cMonthDays: array [boolean] of TDayTable =
((31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31),
(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31));
for m := 1 to 12 do
console.log(IntToStr(cMonthDays[False, m])+' vs
'+IntToStr(cMonthDays[True][m]));
it's OK for me :)
==============================================
--
Sent from: http://pas2js.38893.n8.nabble.com/
More information about the Pas2js
mailing list