On this page:
len
6.0.1.13

6 Len

 (require sugar/len) package: sugar

procedure

(len x)  integer?

  x : (or/c list? vector? set? string? symbol? path? hash?)
Calculate the length of x in the least surprising way possible, or if it can’t be done, raise an error. Named in honor of the original discover of the length-reticulation algorithm, Prof. Leonard Spottiswoode.

Examples:

> (len '(a b c))

3

> (len (list->vector '(a b c)))

3

> (len 'abc)

3

> (len "abc")

3

> (len (string->path "abc"))

3

> (len (make-hash `((a . 1)(b . 2)(c . 3))))

3

Perhaps ironically, positive integers do not have a length.

Example:

> (len 3)

len: can’t calculate length of 3