X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=src%2Fscheme-library-5-lists.scm;fp=src%2Fscheme-library-5-lists.scm;h=12bd3c345f0c026e63a7eb6e160d5ccdb3bc866f;hb=41b469d050586a05cd43fdd4c78755616af3f7b4;hp=0000000000000000000000000000000000000000;hpb=34c8e9e803a2257d9234b1381ad4eef725e224da;p=scheme.forth.jl.git diff --git a/src/scheme-library-5-lists.scm b/src/scheme-library-5-lists.scm new file mode 100644 index 0000000..12bd3c3 --- /dev/null +++ b/src/scheme-library-5-lists.scm @@ -0,0 +1,16 @@ +;; LISTS + +; Return number of items in list +(define (length l) + (define (iter a count) + (if (null? a) + count + (iter (cdr a) (fix:+ count 1)))) + (iter l 0)) + +; Reverse the contents of a list +(define (reverse l) + (if (null? l) + () + (append (reverse (cdr l)) (list (car l))))) +