Array length: Difference between revisions

→‎Forth: use forth highlighting
(→‎Forth: use forth highlighting)
(12 intermediate revisions by 10 users not shown)
Line 580:
orange
</pre>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
Unless modified with OPTION BASE 1 or MAT ORIGIN 1, the lower limit of an array is 1.
<syntaxhighlight lang="qbasic">10 dim fruta$(2)
20 read fruta$(0),fruta$(1),fruta$(2)
30 data "apple","orange","lemon"
40 print "The length of the array 'fruit$' is ";ubound(fruta$)+1
50 end</syntaxhighlight>
 
==={{header|Commodore BASIC}}===
Line 605 ⟶ 614:
 
==={{header|True BASIC}}===
<syntaxhighlight lang="qbasic">DIM fruta$(2)
DIM fruta$(2)
READ fruta$(1), fruta$(2)
DATA "apple", "orange"
Line 613 ⟶ 621:
 
PRINT "La longitud del array fruta$ es" ; tamano
END</syntaxhighlight>
END
</syntaxhighlight>
 
{{out}}
<pre> La longitud del array fruta$ es 2 </pre>
Line 622 ⟶ 628:
True BASIC's arrays are not fixed in length and, although True BASIC is a compiled-language, the number of elements can be changed during runtime using such functions as the MAT REDIM (matrix re-dimension) function. Although the starting index of 1 is in implicit, it can be changed by setting the lower and upper bounds (eg. fruit(0 to 3)) when declaring the array. Also, the example below uses the MAT READ function to read in the data elements into the array without having to explicitly list each variable-array index. The example also uses the SIZE function vs the bounds method to determine the length of the array. Finally, in this example the SIZE function was not assigned to a separate variable and instead is used within the PRINT function itself.
 
<syntaxhighlight lang="qbasic">DIM fruit$(2)
DIM fruit$(2)
MAT READ fruit$
DATA "apple", "orange"
 
PRINT "The length of the array 'fruit$' is "; SIZE(fruit$)
END</syntaxhighlight>
END
{{out}}
</syntaxhighlight>
<pre> The length of the array 'fruit$' is 2 </pre>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "Array length"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
 
FUNCTION Entry ()
DIM F$[2]
F$[0] = "apple"
F$[1] = "orange"
F$[2] = "pear"
 
PRINT "The length of the fruit array is "; UBOUND(F$[])
PRINT F$[1]
END FUNCTION
END PROGRAM</syntaxhighlight>
{{out}}
<pre> The length of the fruit array 'fruit$' is 2 </pre>2
orange</pre>
 
=={{header|Batch File}}==
Line 710 ⟶ 733:
p ["apple", "orange"].length
</syntaxhighlight>
 
=={{header|Binary Lambda Calculus}}==
 
BLC has no arrays, so here's a function to compute the length of a given list (as a church numeral) instead, corresponding to https://github.com/tromp/AIT/blob/master/lists/length.lam :
 
<pre>010001101000000101100000000000011100101010111111110111111101111011010000010</pre>
 
=={{header|BQN}}==
Line 1,327 ⟶ 1,356:
</syntaxhighlight>
 
=={{header|Dyalectdt}}==
<syntaxhighlight lang="dt">[ "apple" "orange" ] len</syntaxhighlight>
 
=={{header|Dyalect}}==
<syntaxhighlight lang="dyalect">var xs = ["apple", "orange"]
print(xs.Length())</syntaxhighlight>
Line 1,374 ⟶ 1,405:
|> Array.fromList
|> Array.length
|> BasicsString.toStringfromInt
|> Html.text
</syntaxhighlight>
Line 1,430 ⟶ 1,461:
{ "apple" "orange" } length
</syntaxhighlight>
 
=={{header|Fennel}}==
<syntaxhighlight lang="fennel">(length [:apple :orange])</syntaxhighlight>
 
=={{header|Forth}}==
Line 1,437 ⟶ 1,471:
The code is commented to explain what is going on for those unfamiliar with Forth.
 
<syntaxhighlight lang="textforth">: STRING, ( caddr len -- ) \ Allocate space & compile string into memory
HERE OVER CHAR+ ALLOT PLACE ;
 
Line 1,792 ⟶ 1,826:
length(a)
</syntaxhighlight>
 
=={{header|K}}==
<syntaxhighlight lang="k">#("apple";"orange")</syntaxhighlight>
{{out}}
<pre>2</pre>
 
=={{header|Klingphix}}==
Line 1,839 ⟶ 1,878:
 
<syntaxhighlight lang="latitude">println: ["apple", "orange"] length.</syntaxhighlight>
 
=={{header|LDPL}}==
<syntaxhighlight lang="ldpl">data:
fruits is text list
len is number
 
procedure:
push "apple" to fruits
push "orange" to fruits
get length of fruits in len
display len lf
</syntaxhighlight>
{{out}}
<pre>
2
</pre>
 
=={{header|Liberty BASIC}}==
Line 2,183 ⟶ 2,238:
<pre>
The length of the fruit array is 2
</pre>
 
=={{header|Nu}}==
<syntaxhighlight lang="nu">
[apple orange] | length
</syntaxhighlight>
{{out}}
<pre>
2
</pre>
 
Line 2,831 ⟶ 2,895:
=={{heaer|Slope}}==
<syntaxhighlight lang="slope">(length ["apple" "orange"])</syntaxhighlight>
 
=={{header|SmallBASIC}}==
<syntaxhighlight lang="SmallBASIC">
A = ["apple", "orange"]
print len(A)
</syntaxhighlight>
 
=={{header|Smalltalk}}==
Line 3,112 ⟶ 3,182:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">var arr = ["apple", "orange"]
System.print(arr.count)</syntaxhighlight>
 
62

edits