re-dimensioning_20arrays
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| re-dimensioning_20arrays [2018/04/17 18:21] – Added syntax highlighting tbest3112 | re-dimensioning_20arrays [2024/01/05 00:22] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| =====Re-dimensioning arrays===== | =====Re-dimensioning arrays===== | ||
| - | //by Richard Russell, May 2014//\\ \\ BBC BASIC does not have a **REDIM** or **REDIM PRESERVE** statement, as found in some other dialects of BASIC (REDIM allows you to increase the dimensions of an existing array - the contents are lost - and REDIM PRESERVE allows you to increase the dimensions of an array without destroying its contents). However it is not difficult to provide an equivalent functionality using user-defined procedures: | + | //by Richard Russell, May 2014//\\ \\ BBC BASIC does not have a **REDIM** or **REDIM PRESERVE** statement, as found in some other dialects of BASIC (REDIM allows you to increase the dimensions of an existing array - the contents are lost - and REDIM PRESERVE allows you to increase the dimensions of an array without destroying its contents). However it is not difficult to provide an equivalent functionality using user-defined procedures |
| <code bb4w> | <code bb4w> | ||
| DEF PROCredim1d(RETURN P%,S%,D%) | DEF PROCredim1d(RETURN P%,S%,D%) | ||
| Line 72: | Line 72: | ||
| PROCredim1d(array$(), | PROCredim1d(array$(), | ||
| </ | </ | ||
| - | \\ | + | |
| + | Here are equivalent procedures for //BBC BASIC for SDL 2.0//: | ||
| + | |||
| + | <code bb4w> | ||
| + | DEF PROCredim1d(RETURN p%%, | ||
| + | LOCAL a%%,N% | ||
| + | IF ? | ||
| + | N% = 5+S%*(D%+1) | ||
| + | IF p%%< | ||
| + | SYS " | ||
| + | IF @platform% AND &40 ELSE a%%=!^a%% | ||
| + | IF a%%=0 ERROR 11, "DIM space" | ||
| + | SYS " | ||
| + | ?a%%=1 : a%%!1=D%+1 | ||
| + | p%% = a%% | ||
| + | ENDPROC | ||
| + | |||
| + | DEF PROCredim2d(RETURN p%%, | ||
| + | LOCAL a%%,N% | ||
| + | IF ? | ||
| + | N% = 9+S%*(D%+1)*(E%+1) | ||
| + | IF p%%< | ||
| + | SYS " | ||
| + | IF @platform% AND &40 ELSE a%%=!^a%% | ||
| + | IF a%%=0 ERROR 11, "DIM space" | ||
| + | SYS " | ||
| + | ?a%%=2 : a%%!1=D%+1 : a%%!5=E%+1 | ||
| + | p%% = a%% | ||
| + | ENDPROC | ||
| + | |||
| + | DEF PROCredimpreserve1d(RETURN p%%, | ||
| + | LOCAL a%%,N%,O% | ||
| + | IF ? | ||
| + | N% = 5+S%*(D%+1) | ||
| + | O% = 5+S%*p%%!1 | ||
| + | SYS " | ||
| + | IF @platform% AND &40 ELSE a%%=!^a%% | ||
| + | IF a%%=0 ERROR 11, "DIM space" | ||
| + | SYS " | ||
| + | IF N%>O% SWAP N%,O% | ||
| + | SYS " | ||
| + | a%%!1=D%+1 | ||
| + | IF p%%< | ||
| + | p%% = a%% | ||
| + | ENDPROC | ||
| + | |||
| + | DEF PROCredimpreserve2d(RETURN p%%, | ||
| + | LOCAL a%%,N%,O% | ||
| + | IF ? | ||
| + | N% = 9+S%*(D%+1)*(E%+1) | ||
| + | O% = 9+S%*p%%!1*p%%!5 | ||
| + | SYS " | ||
| + | IF @platform% AND &40 ELSE a%%=!^a%% | ||
| + | IF a%%=0 ERROR 11, "DIM space" | ||
| + | SYS " | ||
| + | IF N%>O% SWAP N%,O% | ||
| + | SYS " | ||
| + | a%%!1=D%+1 : a%%!5=E%+1 | ||
| + | IF p%%< | ||
| + | p%% = a%% | ||
| + | ENDPROC | ||
| + | </ | ||
| + | |||
| + | The most reliable way of determining the element size is to calculate it at run-time, as in the above examples, but for reference here are the appropriate sizes for each type of array:\\ | ||
| | **byte** e.g. array& | | **byte** e.g. array& | ||
| Line 82: | Line 145: | ||
| | **64-bit integer** e.g. array%%() \\ | size=**8***\\ | | | **64-bit integer** e.g. array%%() \\ | size=**8***\\ | | ||
| | **80-bit float** e.g. array()\\ | size=**10***\\ | | | **80-bit float** e.g. array()\\ | size=**10***\\ | | ||
| - | * BB4W version 6 only | + | * BB4W version 6 or BBCSDL |
re-dimensioning_20arrays.1523989283.txt.gz · Last modified: 2024/01/05 00:16 (external edit)