fork download
  1. ; length
  2.  
  3. (define (len xs)
  4. (if (null? xs)
  5. 0
  6. (+ 1 (len (cdr xs)))))
  7.  
  8. (display (len '(a b c d e f g))) (newline)
  9.  
  10. (define (len-aux xs n)
  11. (if (null? xs)
  12. n
  13. (len-aux (cdr xs) (+ n 1))))
  14.  
  15. (define (len xs)
  16. (len-aux xs 0))
  17.  
  18. (display (len '(a b c d e f g))) (newline)
  19.  
  20. (define (len xs)
  21. (let loop ((xs xs) (n 0))
  22. (if (null? xs)
  23. n
  24. (loop (cdr xs) (+ n 1)))))
  25.  
  26. (display (len '(a b c d e f g))) (newline)
  27.  
  28. (define (shorter? xs ys)
  29. (cond ((null? ys) #f)
  30. ((null? xs) #t)
  31. (else (shorter? (cdr xs) (cdr ys)))))
  32.  
  33. (display (shorter? '(a b c d e f g) '(h i j k l m n o p))) (newline)
Success #stdin #stdout 0.03s 8152KB
stdin
Standard input is empty
stdout
7
7
7
#t