-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update features.md, mention varlength arrays
- Loading branch information
Showing
5 changed files
with
215 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//Function that returns an array of arbitrary length | ||
FUNCTION arr(x: INTEGER) RETURNS ARRAY OF INTEGER | ||
DECLARE out: ARRAY[1:x] OF INTEGER | ||
RETURN out | ||
ENDFUNCTION | ||
|
||
TYPE pArray = ^ARRAY OF INTEGER | ||
CLASS bar | ||
PUBLIC field: ARRAY OF INTEGER | ||
PUBLIC PROCEDURE NEW(len: INTEGER) | ||
//The field is assigned to before it is used, so it does not need to be initialized | ||
field <- arr(len) | ||
ENDPROCEDURE | ||
ENDCLASS | ||
|
||
DECLARE x: bar | ||
DECLARE y: pArray | ||
|
||
x <- NEW bar(1) | ||
y <- ^x.field //Create a pointer to x.field | ||
|
||
FOR i <- 1 TO LENGTH(x.field) //Loop through x.field | ||
OUTPUT x.field[i] | ||
NEXT i | ||
|
||
FOR i <- 1 TO LENGTH(y^) //Loop through the pointer | ||
OUTPUT (y^)[i] | ||
NEXT i | ||
|
||
//Replace x.field with an array of different type | ||
x.field <- arr(2) | ||
|
||
//The pointer should still be pointing to x.field | ||
FOR i <- 1 TO LENGTH(y^) | ||
OUTPUT (y^)[i] | ||
NEXT i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters