Logo

Programming-Idioms

History of Idiom 117 > diff from v23 to v24

Edit summary for version 24 by :
Restored version 22

Version 23

2016-02-18, 16:58:03

Version 24

2016-02-18, 18:55:55

Idiom #117 Get list size

Set n to the number of elements of list x.

Idiom #117 Get list size

Set n to the number of elements of list x.

Imports
with Ada.Containers.Vectors;
use Ada.Containers;
Code
N : Count_Type := X.Length;
Code
let n = x.len();

Code
let n = x.len();

Doc URL
http://rustbyexample.com/primitives/array.html
Doc URL
http://rustbyexample.com/primitives/array.html
Code
my $N = @x;
Code
my $N = @x;
Comments bubble
I like to be more explicit, using $N = scalar @x; but some people consider that overly verbose.
Comments bubble
I like to be more explicit, using $N = scalar @x; but some people consider that overly verbose.
Code
n := length(x);
Code
n := length(x);
Comments bubble
x is some type of array.
Comments bubble
x is some type of array.
Code
n := len(x)
Code
n := len(x)
Comments bubble
x is a slice or an array.
Comments bubble
x is a slice or an array.
Doc URL
https://golang.org/pkg/builtin/#len
Doc URL
https://golang.org/pkg/builtin/#len
Demo URL
http://play.golang.org/p/e-8WVe52yM
Demo URL
http://play.golang.org/p/e-8WVe52yM