You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sugar/len.rkt

15 lines
393 B
Racket

#lang racket/base
11 years ago
(require racket/set)
(provide len)
11 years ago
(define (len x)
(cond
[(list? x) (length x)]
[(string? x) (string-length x)]
[(symbol? x) (len (symbol->string x))]
11 years ago
[(vector? x) (vector-length x)]
[(hash? x) (len (hash-keys x))]
[(integer? x) (len (number->string x))]
11 years ago
[(set? x) (len (set->list x))]
[else (error "len: cant calculate length of" x)]))