Array length: Difference between revisions
→{{header|Commodore BASIC}}: Solution was counting total length of strings in the array instead of reporting the size of the array.
(→{{header|AppleScript}}: Added a note to the first of the existing scripts.) |
(→{{header|Commodore BASIC}}: Solution was counting total length of strings in the array instead of reporting the size of the array.) |
||
Line 542:
==={{header|Commodore BASIC}}===
Commodore BASIC has no way within the language to query an array for its length, but you can dive into the implementation to get that information. On a C-64 in particular, this works:
<lang basic>10 DIM A$(2)▼
{{works with|Commodore BASIC|2.0 on C-64}}
20 A$(1) = "ORANGE"▼
30 A$(2) = "APPLE"▼
40 AT=0:N$="":T=0:L=0:REM DECLARE ALL VARS BEFORE PEEKING
50 AT=PEEK(47)+256*PEEK(48):REM START OF ARRAYS IN MEMORY
60 N$=CHR$(PEEK(AT)AND127)+CHR$(PEEK(AT+1)AND127):REM NAME
70 T=(PEEK(AT) AND 128)*2+(PEEK(AT+1)AND128):REM TYPE
80 IF T=384 THEN N$=N$+"%": REM INTEGER
90 IF T=128 THEN N$=N$+"$": REM STRING
100 L=PEEK(AT+6): REM FIRST INDEX SIZE
110 PRINT N$" HAS"L"ELEMENTS."</lang>
{{Out}}
<pre>A$ HAS 2 ELEMENTS.</pre>
==={{header|True BASIC}}===
|