From: Tim Vaughan Date: Sun, 6 Nov 2016 08:53:01 +0000 (+1300) Subject: Added (length) X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=069f0a8c965a6b7277f5ba8a3f939c69d787838e;p=scheme.forth.jl.git Added (length) --- diff --git a/scheme-library.scm b/scheme-library.scm index f95ed65..484f500 100644 --- a/scheme-library.scm +++ b/scheme-library.scm @@ -13,6 +13,14 @@ (define (cddr l) (cdr (cdr l))) (define (cadar l) (car (cdr (car l)))) +; Return number of items in list +(define (length l) + (define (iter a count) + (if (null? a) + count + (iter (cdr a) (+ count 1)))) + (iter l 0)) + ; Join two lists together (define (join l1 l2) (if (null? l1)