Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,4 @@
---
category:
- Simple
from: http://rosettacode.org/wiki/Array_length

View file

@ -0,0 +1,10 @@
;Task:
Determine the amount of elements in an array.
As an example use an array holding the strings 'apple' and 'orange'.
{{Template:Strings}}
<br><br>

View file

@ -0,0 +1 @@
print([apple, orange].len)

View file

@ -0,0 +1,12 @@
* Array length 22/02/2017
ARRAYLEN START
USING ARRAYLEN,12
LR 12,15 end of prolog
LA 1,(AEND-A)/L'A hbound(a)
XDECO 1,PG+13 edit
XPRNT PG,L'PG print
BR 14 exit
A DC CL6'apple',CL6'orange' array
AEND DC 0C
PG DC CL25'Array length=' buffer
END ARRAYLEN

View file

@ -0,0 +1,8 @@
start:
LDA #(Array_End-Array) ;evaluates to 13
RTS
Array:
byte "apple",0
byte "orange",0
Array_End:

View file

@ -0,0 +1,15 @@
start:
MOVE.B #(MyArray_End-MyArray)/4 ;evaluates to 2
RTS
Apple:
DC.B "apple",0
even
Orange:
DC.B "orange",0
even
MyArray:
DC.L Apple
DC.L Orange
MyArray_End:

View file

@ -0,0 +1 @@
["apples", "oranges"] a:len . cr

View file

@ -0,0 +1,64 @@
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program lenAreaString64.s */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
/*******************************************/
/* Initialized data */
/*******************************************/
.data
szMessLenArea: .asciz "The length of area is : @ \n"
szCarriageReturn: .asciz "\n"
/* areas strings */
szString1: .asciz "Apples"
szString2: .asciz "Oranges"
/* pointer items area */
tablesPoi:
ptApples: .quad szString1
ptOranges: .quad szString2
ptVoid: .quad 0
/*******************************************/
/* UnInitialized data */
/*******************************************/
.bss
sZoneConv: .skip 30
/*******************************************/
/* code section */
/*******************************************/
.text
.global main
main: // entry of program
ldr x1,qAdrtablesPoi // begin pointer table
mov x0,0 // counter
1: // begin loop
ldr x2,[x1,x0,lsl 3] // read string pointer address item x0 (8 bytes by pointer)
cmp x2,0 // is null ?
cinc x0,x0,ne // no increment counter
bne 1b // and loop
ldr x1,qAdrsZoneConv // conversion decimal
bl conversion10S
ldr x0,qAdrszMessLenArea
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // insert result at @ character
bl affichageMess
100: // standard end of the program
mov x0,0 // return code
mov x8,EXIT // request to exit program
svc 0 // perform the system call
qAdrtablesPoi: .quad tablesPoi
qAdrszMessLenArea: .quad szMessLenArea
qAdrsZoneConv: .quad sZoneConv
qAdrszCarriageReturn: .quad szCarriageReturn
/********************************************************/
/* File Include fonctions */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"

View file

@ -0,0 +1,5 @@
report z_array_length.
data(internal_table) = value stringtab( ( `apple` ) ( `orange` ) ).
write: internal_table[ 1 ] , internal_table[ 2 ] , lines( internal_table ).

View file

@ -0,0 +1,3 @@
# UPB returns the upper bound of an array, LWB the lower bound #
[]STRING fruits = ( "apple", "orange" );
print( ( ( UPB fruits - LWB fruits ) + 1, newline ) ) # prints 2 #

View file

@ -0,0 +1,3 @@
array: seq["apple"; "orange"]
length[array]
/Works as a one liner: length[seq["apple"; "orange"]]

View file

@ -0,0 +1 @@
'apple' 'orange'

View file

@ -0,0 +1,134 @@
/* ARM assembly Raspberry PI */
/* program lenAreaString.s */
/* Constantes */
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ WRITE, 4 @ Linux syscall
/* Initialized data */
.data
szMessLenArea: .ascii "The length of area is : "
sZoneconv: .fill 12,1,' '
szCarriageReturn: .asciz "\n"
/* areas strings */
szString1: .asciz "Apples"
szString2: .asciz "Oranges"
/* pointer items area */
tablesPoi:
ptApples: .int szString1
ptOranges: .int szString2
ptVoid: .int 0
/* UnInitialized data */
.bss
/* code section */
.text
.global main
main: /* entry of program */
push {fp,lr} /* saves 2 registers */
ldr r1,iAdrtablesPoi @ begin pointer table
mov r0,#0 @ counter
1: @ begin loop
ldr r2,[r1,r0,lsl #2] @ read string pointer address item r0 (4 bytes by pointer)
cmp r2,#0 @ is null ?
addne r0,#1 @ no increment counter
bne 1b @ and loop
ldr r1,iAdrsZoneconv @ conversion decimal
bl conversion10S
ldr r0,iAdrszMessLenArea
bl affichageMess
2:
100: /* standard end of the program */
mov r0, #0 @ return code
pop {fp,lr} @restaur 2 registers
mov r7, #EXIT @ request to exit program
swi 0 @ perform the system call
iAdrtablesPoi: .int tablesPoi
iAdrszMessLenArea: .int szMessLenArea
iAdrsZoneconv: .int sZoneconv
iAdrszCarriageReturn: .int szCarriageReturn
/******************************************************************/
/* display text with size calculation */
/******************************************************************/
/* r0 contains the address of the message */
affichageMess:
push {fp,lr} /* save registres */
push {r0,r1,r2,r7} /* save others registers */
mov r2,#0 /* counter length */
1: /* loop length calculation */
ldrb r1,[r0,r2] /* read octet start position + index */
cmp r1,#0 /* if 0 its over */
addne r2,r2,#1 /* else add 1 in the length */
bne 1b /* and loop */
/* so here r2 contains the length of the message */
mov r1,r0 /* address message in r1 */
mov r0,#STDOUT /* code to write to the standard output Linux */
mov r7, #WRITE /* code call system "write" */
swi #0 /* call systeme */
pop {r0,r1,r2,r7} /* restaur others registers */
pop {fp,lr} /* restaur des 2 registres */
bx lr /* return */
/***************************************************/
/* conversion register signed décimal */
/***************************************************/
/* r0 contient le registre */
/* r1 contient l adresse de la zone de conversion */
conversion10S:
push {r0-r5,lr} /* save des registres */
mov r2,r1 /* debut zone stockage */
mov r5,#'+' /* par defaut le signe est + */
cmp r0,#0 /* nombre négatif ? */
movlt r5,#'-' /* oui le signe est - */
mvnlt r0,r0 /* et inversion en valeur positive */
addlt r0,#1
mov r4,#10 /* longueur de la zone */
1: /* debut de boucle de conversion */
bl divisionpar10 /* division */
add r1,#48 /* ajout de 48 au reste pour conversion ascii */
strb r1,[r2,r4] /* stockage du byte en début de zone r5 + la position r4 */
sub r4,r4,#1 /* position précedente */
cmp r0,#0
bne 1b /* boucle si quotient different de zéro */
strb r5,[r2,r4] /* stockage du signe à la position courante */
subs r4,r4,#1 /* position précedente */
blt 100f /* si r4 < 0 fin */
/* sinon il faut completer le debut de la zone avec des blancs */
mov r3,#' ' /* caractere espace */
2:
strb r3,[r2,r4] /* stockage du byte */
subs r4,r4,#1 /* position précedente */
bge 2b /* boucle si r4 plus grand ou egal a zero */
100: /* fin standard de la fonction */
pop {r0-r5,lr} /*restaur desregistres */
bx lr
/***************************************************/
/* division par 10 signé */
/* Thanks to http://thinkingeek.com/arm-assembler-raspberry-pi/*
/* and http://www.hackersdelight.org/ */
/***************************************************/
/* r0 contient le dividende */
/* r0 retourne le quotient */
/* r1 retourne le reste */
divisionpar10:
/* r0 contains the argument to be divided by 10 */
push {r2-r4} /* save registers */
mov r4,r0
ldr r3, .Ls_magic_number_10 /* r1 <- magic_number */
smull r1, r2, r3, r0 /* r1 <- Lower32Bits(r1*r0). r2 <- Upper32Bits(r1*r0) */
mov r2, r2, ASR #2 /* r2 <- r2 >> 2 */
mov r1, r0, LSR #31 /* r1 <- r0 >> 31 */
add r0, r2, r1 /* r0 <- r2 + r1 */
add r2,r0,r0, lsl #2 /* r2 <- r0 * 5 */
sub r1,r4,r2, lsl #1 /* r1 <- r4 - (r2 * 2) = r4 - (r0 * 10) */
pop {r2-r4}
bx lr /* leave function */
bx lr /* leave function */
.Ls_magic_number_10: .word 0x66666667

View file

@ -0,0 +1,12 @@
#include
"share/atspre_staload.hats"
#include
"share/atspre_staload_libats_ML.hats"
val A0 =
array0_tuple<string>
( "apple", "orange" )
val () =
println!("length(A0) = ", length(A0))
implement main0((*void*)) = ((*void*))

View file

@ -0,0 +1,15 @@
# usage: awk -f arraylen.awk
#
function countElements(array) {
for( e in array ) {c++}
return c
}
BEGIN {
array[1] = "apple"
array[2] = "orange"
print "Array length :", length(array), countElements(array)
print "String length:", array[1], length(array[1])
}

View file

@ -0,0 +1,14 @@
with Ada.Text_IO; use Ada.Text_IO;
procedure Array_Length is
Fruits : constant array (Positive range <>) of access constant String
:= (new String'("orange"),
new String'("apple"));
begin
for Fruit of Fruits loop
Ada.Text_IO.Put (Integer'Image (Fruit'Length));
end loop;
Ada.Text_IO.Put_Line (" Array Size : " & Integer'Image (Fruits'Length));
end Array_Length;

View file

@ -0,0 +1 @@
System.debug(new String[] { 'apple', 'banana' }.size()); // Prints 2

View file

@ -0,0 +1,6 @@
set theList to {"apple", "orange"}
count theList
-- or
length of theList
-- or
number of items in theList

View file

@ -0,0 +1,41 @@
on run
set xs to ["alpha", "beta", "gamma", "delta", "epsilon", ¬
"zeta", "eta", "theta", "iota", "kappa", "lambda", "mu"]
{_length(xs), fold(xs, succ, 0), item 12 of xs, item -1 of xs}
--> {12, 12, "mu", "mu"}
end run
-- TWO FUNCTIONAL DEFINITIONS OF LENGTH
-- 1. Recursive definition
on _length(xs)
if xs is [] then
0
else
1 + _length(rest of xs)
end if
end _length
-- 2. fold (λx n -> 1 + n) 0
on succ(x)
1 + x
end succ
--[a] - > (a - > b) - > b - > [b]
on fold(xs, f, startValue)
script mf
property lambda : f
end script
set v to startValue
repeat with x in xs
set v to mf's lambda(v, x)
end repeat
end fold

View file

@ -0,0 +1,34 @@
10 DIM A$(2)
20 A$(1) = "ORANGE"
30 A$(2) = "APPLE"
40 N$ = "A$": GOSUB 70: PRINT L$
60 PRINT
61 DIM A%(19,63,0),A3(4,5)
62 N$ = "A%": GOSUB 70: PRINT L$
63 N$ = "A3": GOSUB 70: PRINT L$
64 N$ = "COMMODORE"
65 GOSUB 70: PRINT L$: END
70 L$ = "":N0 = 0:N1 = 0
71 N0$ = LEFT$ (N$,1)
72 N1$ = MID$ (N$,2,2)
73 N1 = RIGHT$ (N$,1) = "$"
74 N0 = RIGHT$ (N$,1) = "%"
75 IF N0 THEN N1 = 1
76 I = LEN (N1$) - N1
77 N1$ = MID$ (N1$,1,I)
78 A = ASC (N1$ + CHR$ (0))
79 N1 = 128 * N1 + A
80 N0 = 128 * N0 + ASC (N0$)
90 DEF FN P(A) = PEEK (A) + PEEK (A + 1) * 256
100 I = FN P(109):A = FN P(107)
110 FOR A = A TO I STEP 0
128 IF PEEK (A) < > N0 OR PEEK (A + 1) < > N1 THEN A = A + FN P(A + 2): NEXT A: PRINT "ARRAY "N$" NOT FOUND": STOP
130 N0 = A + 4
140 N1 = N0 + FN P(N0) * 2
150 N0 = N0 + 2
160 FOR I = N1 TO N0 STEP - 2
170 L$ = L$ + STR$ ( FN P(I))
180 L$ = L$ + " ": NEXT I
190 RETURN

View file

@ -0,0 +1,3 @@
fruit: ["apple" "orange"]
print ["array length =" size fruit]

View file

@ -0,0 +1 @@
MsgBox % ["apple","orange"].MaxIndex()

View file

@ -0,0 +1,9 @@
Opt('MustDeclareVars',1) ; 1 = Variables must be pre-declared.
Local $aArray[2] = ["Apple", "Orange"]
Local $Max = UBound($aArray)
ConsoleWrite("Elements in array: " & $Max & @CRLF)
For $i = 0 To $Max - 1
ConsoleWrite("aArray[" & $i & "] = '" & $aArray[$i] & "'" & @CRLF)
Next

View file

@ -0,0 +1 @@
|<"Apple", "Orange">|

View file

@ -0,0 +1,4 @@
DIM X$(1 TO 2)
X$(1) = "apple"
X$(2) = "orange"
PRINT UBOUND(X$) - LBOUND(X$) + 1

View file

@ -0,0 +1,6 @@
fruta$ = {"apple", "orange", "pear"}
print length(fruta$)
print fruta$[?]
print fruta$[1]
end

View file

@ -0,0 +1,5 @@
DIM array$(1)
array$() = "apple", "orange"
PRINT "Number of elements in array = "; DIM(array$(), 1) + 1
PRINT "Number of bytes in all elements combined = "; SUMLEN(array$())
END

View file

@ -0,0 +1 @@
1"a"+

View file

@ -0,0 +1 @@
3

View file

@ -0,0 +1,18 @@
' Static arrays
DECLARE fruit$[] = { "apple", "orange" }
PRINT UBOUND(fruit$)
' Dynamic arrays
DECLARE vegetable$ ARRAY 2
vegetable$[0] = "cabbage"
vegetable$[1] = "spinach"
PRINT UBOUND(vegetable$)
' Associative arrays
DECLARE meat$ ASSOC STRING
meat$("first") = "chicken"
meat$("second") = "pork"
PRINT UBOUND(meat$)

View file

@ -0,0 +1,28 @@
@echo off
:_main
setlocal enabledelayedexpansion
:: This block of code is putting a list delimitered by spaces into an pseudo-array
:: In practice, this could be its own function _createArray however for the demonstration, it is built in
set colour_list=red yellow blue orange green
set array_entry=0
for %%i in (%colour_list%) do (
set /a array_entry+=1
set colours[!array_entry!]=%%i
)
call:_arrayLength colours
echo _arrayLength returned %errorlevel%
pause>nul
exit /b
:: _arrayLength returns the length of the array parsed to it in the errorcode
:_arrayLength
setlocal enabledelayedexpansion
:loop
set /a arrayentry=%arraylength%+1
if "!%1[%arrayentry%]!"=="" exit /b %arraylength%
set /a arraylength+=1
goto loop

View file

@ -0,0 +1,14 @@
using System;
namespace ArrayLength
{
class Program
{
public static void Main()
{
var array = new String[]("apple", "orange");
Console.WriteLine(array.Count);
delete(array);
}
}
}

View file

@ -0,0 +1 @@
p ["apple", "orange"].length

View file

@ -0,0 +1,10 @@
#include <array>
#include <iostream>
#include <string>
int main()
{
std::array<std::string, 2> fruit { "apples", "oranges" };
std::cout << fruit.size();
return 0;
}

View file

@ -0,0 +1,4 @@
std::vector<std::string> fruitV({ "apples", "oranges" });
std::list<std::string> fruitL({ "apples", "oranges" });
std::deque<std::string> fruitD({ "apples", "oranges" });
std::cout << fruitV.size() << fruitL.size() << fruitD.size() << std::endl;

View file

@ -0,0 +1,10 @@
using System;
class Program
{
public static void Main()
{
var fruit = new[] { "apple", "orange" };
Console.WriteLine(fruit.Length);
}
}

View file

@ -0,0 +1,5 @@
var fruit = new[] { "apple", "orange" };
var fruit = new string[] { "apple", "orange" };
string[] fruit = new[] { "apple", "orange" };
string[] fruit = new string[] { "apple", "orange" };
string[] fruit = { "apple", "orange" };

View file

@ -0,0 +1,9 @@
using static System.Console;
class Program
{
public static void Main()
{
WriteLine(new[] { "apples", "oranges" }.Length);
}
}

View file

@ -0,0 +1,21 @@
#include <stdio.h>
int main()
{
const char *fruit[2] = { "apples", "oranges" };
// Acquire the length of the array by dividing the size of all elements (found
// with sizeof(fruit)) by the size of the first element.
// Note that since the array elements are pointers to null-terminated character
// arrays, the size of the first element is actually the size of the pointer
// type - not the length of the string.
// This size, regardless of the type being pointed to, is 8 bytes, 4 bytes, or
// 2 bytes on 64-bit, 32-bit, or 16-bit platforms respectively.
int length = sizeof(fruit) / sizeof(fruit[0]);
printf("%d\n", length);
return 0;
}

View file

@ -0,0 +1 @@
#define ARRAY_LENGTH(A) (sizeof(A) / sizeof(A[0]))

View file

@ -0,0 +1,76 @@
#define _CRT_SECURE_NO_WARNINGS // turn off panic warnings
#define _CRT_NONSTDC_NO_WARNINGS // enable old-gold POSIX names in MSVS
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
struct StringArray
{
size_t sizeOfArray;
size_t numberOfElements;
char** elements;
};
typedef struct StringArray* StringArray;
StringArray StringArray_new(size_t size)
{
StringArray this = calloc(1, sizeof(struct StringArray));
if (this)
{
this->elements = calloc(size, sizeof(int));
if (this->elements)
this->sizeOfArray = size;
else
{
free(this);
this = NULL;
}
}
return this;
}
void StringArray_delete(StringArray* ptr_to_this)
{
assert(ptr_to_this != NULL);
StringArray this = (*ptr_to_this);
if (this)
{
for (size_t i = 0; i < this->sizeOfArray; i++)
free(this->elements[i]);
free(this->elements);
free(this);
this = NULL;
}
}
void StringArray_add(StringArray this, ...)
{
char* s;
va_list args;
va_start(args, this);
while (this->numberOfElements < this->sizeOfArray && (s = va_arg(args, char*)))
this->elements[this->numberOfElements++] = strdup(s);
va_end(args);
}
int main(int argc, char* argv[])
{
StringArray a = StringArray_new(10);
StringArray_add(a, "apple", "orange", NULL);
printf(
"There are %d elements in an array with a capacity of %d elements:\n\n",
a->numberOfElements, a->sizeOfArray);
for (size_t i = 0; i < a->numberOfElements; i++)
printf(" the element %d is the string \"%s\"\n", i, a->elements[i]);
StringArray_delete(&a);
return EXIT_SUCCESS;
}

View file

@ -0,0 +1,112 @@
#define _CRT_SECURE_NO_WARNINGS // turn off panic warnings
#define _CRT_NONSTDC_NO_WARNINGS // enable old-gold POSIX names in MSVS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 10
// Fixed size global arrays
static const int scGlobal[N];
const int cGlobal[N];
static int sGlobal[N];
int Global[N];
#define TEST(A, N) \
do { \
puts(""); \
printf("directly called: sizeof(%8s) = %2d, length = %2d, %s\n",\
#A, \
sizeof(A), \
sizeof(A) / sizeof(int), \
sizeof(A) / sizeof(int) == N ? "pass" : "fail"); \
\
test1(#A, A, N); \
test2(#A, A, N); \
test3(#A, A, N); \
} while (0);
void test1(char* name, int* A, int n)
{
printf("as parameter int* A: sizeof(%8s) = %2d, length = %2d, %s\n",
name,
sizeof(A),
sizeof(A) / sizeof(int),
sizeof(A) / sizeof(int) == n ? "pass" : "fail");
}
void test2(char* name, int A[], int n)
{
printf("as parameter int A[]: sizeof(%8s) = %2d, length = %2d, %s\n",
name,
sizeof(A),
sizeof(A) / sizeof(int),
sizeof(A) / sizeof(int) == n ? "pass" : "fail");
}
void test3(char* name, int A[10], int n)
{
printf("as parameter int A[10]: sizeof(%8s) = %2d, length = %2d, %s\n",
name,
sizeof(A),
sizeof(A) / sizeof(int),
sizeof(A) / sizeof(int) == n ? "pass" : "fail");
}
int main(int argc, char argv[])
{
// Fixed size local arrays (defined inside curly braces block)
static const int scLocal[N];
const int cLocal[N];
static int sLocal[N];
auto int aLocal[N];
int Local[N];
// Fixed size VLA arrays can/should be used instead dynamically alocated
// blocks. VLA has not implemented in Microsoft Visual Studio C.
srand(time(NULL));
int n = N + rand() % 2; // the value of n is unknow in the compile time?
#ifndef _MSC_VER
int vlaLocal[n];
#endif
// Memory blocks as ersatz arrays. This is not all possible ways to allocate
// memory. There are other functions, like LocalAlloc, HeapAlloc, sbreak...
// Don't use alloca in any serious program - this function is really bad
// choice - it can corrupt the program stack and generate a stack overflow.
int* mBlock = (int*)malloc(n * sizeof(int));
int* cBlock = (int*)calloc(n, sizeof(int));
int* aBlock = (int*)_alloca(n * sizeof(int)); // don't use in your programs!
TEST(scGlobal, N);
TEST(cGlobal, N);
TEST(sGlobal, N);
TEST(Global, N);
TEST(scLocal, N);
TEST(cLocal, N);
TEST(sLocal, N);
TEST(aLocal, N);
TEST(Local, N);
#ifndef _MSC_VER
TEST(vlaLocal, n);
#endif
TEST(mBlock, N);
TEST(cBlock, N);
TEST(aBlock, N);
free(mBlock, N);
free(cBlock, N);
// free must not be called on aBlock
return 0;
}

View file

@ -0,0 +1,40 @@
identification division.
program-id. array-length.
environment division.
configuration section.
repository.
function all intrinsic.
data division.
working-storage section.
01 table-one.
05 str-field pic x(7) occurs 0 to 5 depending on t1.
77 t1 pic 99.
procedure division.
array-length-main.
perform initialize-table
perform display-table-info
goback.
initialize-table.
move 1 to t1
move "apples" to str-field(t1)
add 1 to t1
move "oranges" to str-field(t1).
*> add an extra element and then retract table size
add 1 to t1
move "bananas" to str-field(t1).
subtract 1 from t1
.
display-table-info.
display "Elements: " t1 ", using " length(table-one) " bytes"
display table-one
.
end program array-length.

View file

@ -0,0 +1,4 @@
shared void run() {
value array = ["apple", "orange"];
print(array.size);
}

View file

@ -0,0 +1,10 @@
/*
* nizchka: March - 2016
* This is a Clipper/XBase++ of RosettaCode Array_Length
*/
PROCEDURE MAIN()
LOCAL FRUIT := { "apples","oranges" }
? LEN(FRUIT)
RETURN

View file

@ -0,0 +1,5 @@
; using count:
(count ["apple" "orange"])
; OR alength if using Java arrays:
(alength (into-array ["apple" "orange"]))

View file

@ -0,0 +1,2 @@
<cfset testArray = ["apple","orange"]>
<cfoutput>Array Length = #ArrayLen(testArray)#</cfoutput>

View file

@ -0,0 +1,11 @@
10 DIM A$(1):REM 1=LAST -> ROOM FOR 2
20 A$(0) = "ORANGE"
30 A$(1) = "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."

View file

@ -0,0 +1 @@
(print (length #("apple" "orange")))

View file

@ -0,0 +1,8 @@
;; Project : Array length
(setf my-array (make-array '(2)))
(setf (aref my-array 0) "apple")
(setf (aref my-array 1) "orange")
(format t "~a" "length of my-array: ")
(length my-array)
(terpri)

View file

@ -0,0 +1,32 @@
MODULE AryLen;
IMPORT StdLog;
TYPE
String = POINTER TO ARRAY OF CHAR;
VAR
a: ARRAY 16 OF String;
PROCEDURE NewString(s: ARRAY OF CHAR): String;
VAR
str: String;
BEGIN
NEW(str,LEN(s$) + 1);str^ := s$; RETURN str
END NewString;
PROCEDURE Length(a: ARRAY OF String): INTEGER;
VAR
i: INTEGER;
BEGIN
i := 0;
WHILE a[i] # NIL DO INC(i) END;
RETURN i
END Length;
PROCEDURE Do*;
BEGIN
a[0] := NewString("Apple");
a[1] := NewString("Orange");
StdLog.String("Length:> ");StdLog.Int(Length(a));StdLog.Ln
END Do;
END AryLen.

View file

@ -0,0 +1 @@
puts ["apple", "orange"].size

View file

@ -0,0 +1,8 @@
import std.stdio;
int main()
{
auto fruit = ["apple", "orange"];
fruit.length.writeln;
return 0;
}

View file

@ -0,0 +1,6 @@
import std.stdio;
void main()
{
["apple", "orange"].length.writeln;
}

View file

@ -0,0 +1,8 @@
arrLength(arr) {
return arr.length;
}
main() {
var fruits = ['apple', 'orange'];
print(arrLength(fruits));
}

View file

@ -0,0 +1,2 @@
var arr = ["apple", "orange"]
sizeOf(arr)

View file

@ -0,0 +1 @@
showmessage( length(['a','b','c']).ToString );

View file

@ -0,0 +1,5 @@
set_namespace(rosettacode)_me();
me_msg()_array()_values(apple,orange)_length();
reset_namespace[];

View file

@ -0,0 +1,6 @@
select "std"
a = ["apple","orange"]
b = length(a)
show b

View file

@ -0,0 +1,2 @@
var xs = ["apple", "orange"]
print(xs.Length())

View file

@ -0,0 +1 @@
writeLine(text["apple", "orange"].length)

View file

@ -0,0 +1,2 @@
fruit$[] = [ "apples" "oranges" ]
print len fruit$[]

View file

@ -0,0 +1,4 @@
(length '("apple" "orange")) ;; list
→ 2
(vector-length #("apple" "orange")) ;; vector
→ 2

View file

@ -0,0 +1,2 @@
String[] array = ["apple", "orange"];
Int length = array.size;

View file

@ -0,0 +1 @@
length [1..10]

View file

@ -0,0 +1,2 @@
var array := new string[]{"apple", "orange"};
var length := array.Length;

View file

@ -0,0 +1,4 @@
iex(1)> length( ["apple", "orange"] ) # List
2
iex(2)> tuple_size( {"apple", "orange"} ) # Tuple
2

View file

@ -0,0 +1,10 @@
import Array
import Html
main : Html.Html
main =
["apple", "orange"]
|> Array.fromList
|> Array.length
|> Basics.toString
|> Html.text

View file

@ -0,0 +1,2 @@
(length ["apple" "orange"])
=> 2

View file

@ -0,0 +1,4 @@
1> length(["apple", "orange"]). %using a list
2
1> tuple_size({"apple", "orange"}). %using a tuple
2

View file

@ -0,0 +1,18 @@
sequence s = {"apple","orange",2.95} -- Euphoria doesn't care what you put in a sequence
? length(s)
3 -- three objects
? length(s[1])
5 -- apple has 5 characters
? length(s[1][$])
1 -- 'e' is an atomic value
? length(s[$])
1 -- 2.95 is an atomic value

View file

@ -0,0 +1 @@
[|1;2;3|].Length |> printfn "%i"

View file

@ -0,0 +1 @@
[|1;2;3|] |> Array.length |> printfn "%i"

View file

@ -0,0 +1 @@
{ "apple" "orange" } length

View file

@ -0,0 +1,27 @@
: STRING, ( caddr len -- ) \ Allocate space & compile string into memory
HERE OVER CHAR+ ALLOT PLACE ;
: " ( -- ) [CHAR] " PARSE STRING, ; \ Parse input to " and compile to memory
\ Array delimiter words
: { ALIGN 0 C, ; \ Compile 0 byte start/end of array
: } ALIGN 0 C, ;
\ String array words
: {NEXT} ( str -- next_str) \ Iterate to next string
COUNT + ;
: {NTH} ( n array_addr -- str) \ Returns address of the Nth item in the array
SWAP 0 DO {NEXT} LOOP ;
: {LEN} ( array_addr -- n) \ count strings in the array
0 >R \ Counter on Rstack
{NEXT}
BEGIN
DUP C@ \ Fetch length byte
WHILE \ While true
R> 1+ >R \ Inc. counter
{NEXT}
REPEAT
DROP
R> ; \ return counter to data stack

View file

@ -0,0 +1 @@
CREATE Q { " Apples" " Oranges" } q {len} . 2 ok

View file

@ -0,0 +1,20 @@
MODULE EXAMPLE
CONTAINS
SUBROUTINE ABOUND(A)
CHARACTER*(*) A(:) !One dimensional array, unspecified bounds.
WRITE (6,*) "Lower bound",LBOUND(A),", Upper bound",UBOUND(A)
WRITE (6,*) "Element size",LEN(A(LBOUND(A)))
WRITE (6,*) A
END SUBROUTINE ABOUND
END MODULE EXAMPLE
PROGRAM SHOWBOUNDS
USE EXAMPLE
CHARACTER*6 ARRAY(-1:1)
ARRAY(-1) = "Apple"
ARRAY(0) = "Orange"
ARRAY(1) = ""
CALL ABOUND(ARRAY)
WRITE (6,*) "But, when it is at home..."
WRITE (6,*) "L. bound",LBOUND(ARRAY),", U. bound",UBOUND(ARRAY)
END

View file

@ -0,0 +1,8 @@
' FB 1.05.0 Win64
Dim fruit(1) As String = {"apple", "orange"}
Dim length As Integer = UBound(fruit) - LBound(fruit) + 1
Print "The length of the fruit array is"; length
Print
Print "Press any key to quit the program"
Sleep

View file

@ -0,0 +1,2 @@
a = ["apple", "orange"]
println[length[a]]

View file

@ -0,0 +1 @@
fun length(as: []int): int = (shape as)[0]

View file

@ -0,0 +1,3 @@
window 1
print fn ArrayCount( @[@"apple",@"orange",@"cherry",@"grape",@"lemon"] )
HandleEvents

View file

@ -0,0 +1,8 @@
void local fn DoIt
CFArrayRef array = @[@"apple",@"orange",@"cherry",@"grape",@"lemon"]
print len(array)
end fn
fn DoIt
HandleEvents

View file

@ -0,0 +1,6 @@
Public Sub Main()
Dim siList As Short[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
Print siList.Count
End

View file

@ -0,0 +1,6 @@
[indent=4]
/* Array length, in Genie */
init
arr:array of string = {"apple", "orange"}
stdout.printf("%d ", arr.length)
print arr[1]

View file

@ -0,0 +1,9 @@
package main
import "fmt"
func main() {
arr := [...]string{"apple", "orange", "pear"}
fmt.Printf("Length of %v is %v.\n", arr, len(arr))
}

View file

@ -0,0 +1,2 @@
def fruits = ['apple','orange']
println fruits.size()

View file

@ -0,0 +1,2 @@
LOCAL aFruits := {"apple", "orange"}
Qout( Len( aFruits ) ) // --> 2

View file

@ -0,0 +1,2 @@
-- [[Char]] -> Int
length ["apple", "orange"]

View file

@ -0,0 +1,4 @@
let a arr 2
let a[0] "apple"
let a[1] "orange"
println len a

View file

@ -0,0 +1 @@
|= arr=(list *) (lent arr)

View file

@ -0,0 +1 @@
main: print(#["apple", "orange"])

View file

@ -0,0 +1,3 @@
100 STRING X$(1 TO 2)
110 LET X$(1)="apple":LET X$(2)="orange"
120 PRINT "The length of the array 'X$' is";SIZE(X$)

View file

@ -0,0 +1 @@
write(*["apple", "orange"])

View file

@ -0,0 +1 @@
length ["apple", "orange"]

View file

@ -0,0 +1,4 @@
# 'apple';'orange'
2
$ 'apple';'orange'
2

View file

@ -0,0 +1,4 @@
$#'apple';'orange'
$$'apple';'orange'
1

View file

@ -0,0 +1,7 @@
>'apple';'orange'
apple
orange
$>'apple';'orange'
2 6
#>'apple';'orange'
2

View file

@ -0,0 +1,5 @@
9001
9001
#9001
1
$9001

View file

@ -0,0 +1,6 @@
#$9001
0
#$'apple';'orange'
1
#$>'apple';'orange'
2

View file

@ -0,0 +1,2 @@
(def our-array @["apple" "orange"])
(length our-array)

Some files were not shown because too many files have changed in this diff Show more