Skip to content

Instantly share code, notes, and snippets.

@ncweinhold
Created June 6, 2011 22:45
Show Gist options
  • Save ncweinhold/1011280 to your computer and use it in GitHub Desktop.
Save ncweinhold/1011280 to your computer and use it in GitHub Desktop.
different ways of summing lists of numbers
#lang racket
(define (my-sum-1 lst)
(cond
((null? lst) 0)
(else (+ (car lst) (my-sum-1 (cdr lst))))))
(define (my-sum-2 lst)
(define (my-sum-iter res lst)
(cond
((null? lst) res)
(else (my-sum-iter (+ (car lst) res) (cdr lst)))))
(my-sum-iter 0 lst))
(define (my-sum-3 lst)
(apply + lst))
(define (my-range start end)
(cond
((= start end) '())
(else (cons start (my-range (+ 1 start) end)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment