вторник, 11 августа 2015 г.

Briefly. I made type-checking for array elements

Original in Russian: http://programmingmindstream.blogspot.ru/2015/08/blog-post_4.html
Follow-up to - ToDo. Write about arrays, lists and iterators

Briefly. I made type-checking for array elements.

Something like this:

ARRAY VAR A
ARRAY OF STRING VAR B
A := [ 1 2 3 'hello' ] // - compilable
B := [ 1 2 3 'hello' ] // - not compilable

Defining of type

ARRAY VAR A
ARRAY OF STRING TYPE StringArray // - this is an alias for ARRAY OF STRING
StringArray VAR B
A := [ 1 2 3 'hello' ] // - compilable
B := [ 1 2 3 'hello' ] // - not compilable

To make it more complex:

STRING FUNCTION X
 Result := 'hello'
;
 
ARRAY VAR A
ARRAY OF STRING TYPE StringArray // - this is an alias for ARRAY OF STRING
StringArray VAR B
A := [ 1 2 3 X ] // - compilable
B := [ 1 2 3 X ] // - compilable, but throws the Run-Time error

Adding a reference to the function:

STRING FUNCTION X
 Result := 'hello'
;
 
ARRAY VAR A
ARRAY OF STRING TYPE StringArray // - this is an alias for ARRAY OF STRING
StringArray VAR B
A := [ 1 2 3 @ X ] // - compilable
B := [ 1 2 3 @ X ] // - not compilable

Obviously, next, I’ll make output of types and cut the number of Run-time errors in favor of Compile-time.

One more example:

ARRAY VAR A
ARRAY OF STRING TYPE StringArray // - this is an alias for ARRAY OF STRING
ARRAY OF INTEGER TYPE IntegerArray // - this is an alias for ARRAY OF INTEGER
StringArray VAR B
IntegerArray VAR C
A := [ 1 2 3 'hello' ] // - compilable
B := [ 1 2 3 'hello' ] // - not compilable
C := [ 1 2 3 'hello' ] // - not compilable
 
StringArray VAR B1
IntegerArray VAR C1
B1 := [ '1' '2' '3' 'hello' ] // - compilable
C1 := [ 1 2 3 4 ] // - compilable

Sure, there are also ARRAY OF ARRAY OF X:

ARRAY OF ARRAY OF STRING VAR A
A := [ [ 'a' 'b' ] [ 'c' 'd' ] ] // - compilable
A := [ [ 'a' 'b' ] [ 'c' 3 ] ] // - not compilable

The similar is for Run-time:

INTEGER FUNCTION X
 Result := 3
;
 
ARRAY OF ARRAY OF STRING VAR A
A := [ [ 'a' 'b' ] [ 'c' 'd' ] ] // - compilable
A := [ [ 'a' 'b' ] [ 'c' 'd' ] [ 'e' ] ] // - compilable, dimension is not critical
A := [ [ 'a' 'b' ] [ 'c' X ] ] // - compilable, but throws the Run-Time error

Keeping in mind Briefly. I made axiomatic description partly on Delphi, partly on scripts , I can write part of the code on Delphi, part of it on scripts and integrate it all in EXE-file.

At this point, we can use lambdas, iterators and other “delicacies” on Delphi7.


Комментариев нет:

Отправить комментарий