Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are there parentheses and dots after an array's name instead of brackets?

Tags:

syntax

delphi

When accessing an element in an array the square brackets are used like so:

{'X is an int and Numbers is an int array'}
X := Numbers[8];

However, While reading others' code I sometimes find the following syntax:

{'PBox , SBox1 , SBox2 are arrays of int , And X,Y are ints'}
Result := Result or PBox(.SBox1[X] or SBox2[Y].);
  1. What does it mean to have parentheses after the array's name, as in PBox(someNumber)? Is this another way to access an array element?
  2. What does the "." before SBox1 and after SBox2 mean? Both SBox1 and SBox2 are arrays. The code compiles without error but I don't know what those dots are for.
like image 714
Adham Atta Avatar asked Mar 01 '11 16:03

Adham Atta


People also ask

What type of brackets are used for arrays?

We can construct a cell array using curly brackets: '{' and '}'. Recall that we normally use the square brackets '[' and ']' to construct an ordinary array (e.g. see Example 5.7). Here, we initialize a cell array to contain three strings with different lengths.

What do you mean by array?

An array is a data structure consisting of a collection of elements (values or variables), each identified by at least one array index or key. Depending on the language, array types may overlap (or be identified with) other data types that describe aggregates of values, such as lists and strings.

What is an array explain with example?

An array is a variable that can store multiple values. For example, if you want to store 100 integers, you can create an array for it. int data[100];

What is the purpose of an array in programming?

In coding and programming, an array is a collection of items, or data, stored in contiguous memory locations, also known as database systems . The purpose of an array is to store multiple pieces of data of the same type together.


1 Answers

Yes, now I see what you do.

In fact, (. and .) are merely alternative ways (but very uncommon!) of writing [ and ] in Delphi.

If PBox is an array, then PBox[a] (or, equivalently, PBox(.a.)) would require a to be an integer, right? And if SBox1[x] and SBox2[Y] are integers, so is the bitwise or of them. (Bitwise or is an operation that takes two integers and returns a new integer.) Hence, PBox(.SBox1[X] or SBox2[Y].) is the (SBox1[X] or SBox2[Y])th element in the array PBox, that is, an integer. So it makes sense to compute the bitwise or between Result and this integer, which is what is done:

Result := Result or PBox(.SBox1[X] or SBox2[Y].);
like image 88
Andreas Rejbrand Avatar answered Sep 18 '22 07:09

Andreas Rejbrand