Arrays: Difference between revisions

Content added Content deleted
m (→‎{{header|ooRexx}}: add reference to Associative Arrays)
(Add Plain English)
Line 5,544: Line 5,544:
c(7) = 12;
c(7) = 12;
put (C(9));</lang>
put (C(9));</lang>

=={{header|Plain English}}==
Arrays are a bit of a sticking point for Plain English, because its creators have not as yet devised a sufficiently elegant way to work with them within the constraints of the language. Only lists have high-level routine support. Nevertheless, the capability to build arrays ourselves exists within the language. Following is an example of how it could be done.

<lang plainenglish>To run:
Start up.
Write "Creating an array of 100 numbers..." on the console.
Create a number array given 100.
Write "Putting 1 into the array at index 0." on the console.
Put 1 into the number array at 0.
Write "Putting 33 into the array at index 50." on the console.
Put 33 into the number array at 50.
Write "Retrieving value from array at index 0... " on the console without advancing.
Get a number from the number array at 0.
Write "" then the number on the console.
Write "Retrieving value from array at index 50... " on the console without advancing.
Get another number from the number array at 50.
Write "" then the other number on the console.
Write "Retrieving value from array at index 99... " on the console without advancing.
Get a third number from the number array at 99.
Write "" then the third number on the console.
Destroy the number array.
Wait for the escape key.
Shut down.

\\\\\\\\\\\\\\\\\\ Array implementation \\\\\\\\\\\\\\\\\\\\

A number array has a first element pointer.
A location is a number.

To create a number array given a count:
Put a number's magnitude times the count into a size.
Assign the number array's first element pointer given the size. \ allocate memory for the array

To destroy a number array:
Unassign the number array's first element pointer. \ free the array's memory
To get a number from a number array at a location:
Put the location times the number's magnitude into an offset.
Put the number array's first element pointer into a number pointer.
Add the offset to the number pointer.
Put the number pointer's target into the number.
To put a number into a number array at a location:
Put the location times the number's magnitude into an offset.
Put the number array's first element pointer into a number pointer.
Add the offset to the number pointer.
Put the number into the number pointer's target.</lang>
{{out}}
<pre>
Creating an array of 100 numbers...
Putting 1 into the array at index 0.
Putting 33 into the array at index 50.
Retrieving value from array at index 0... 1
Retrieving value from array at index 50... 33
Retrieving value from array at index 99... 0
</pre>


=={{header|Pony}}==
=={{header|Pony}}==