# a3q4 - ; The first three lines of this file were inserted...

This preview shows pages 1–2. Sign up to view the full content.

;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname a3q4) (read-case- sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ()))) ;;CS116 Assignment 3 Question 4 ;; r46wang 20319247 ;;evens: (listof any) -> (listof any) ;;produces the elements of the even positions in the inputted list (starting at position 0) ;;Examples: ;;(evens empty) => empty ;;(evens '(0)) => '(0) ;;(evens '(0 1)) => '(0) ;;(evens '(0 1 2 3 4 5 6)) => '(0 2 4 6) (define (evens lst) (cond [(or(empty? lst)(empty? (rest lst))) lst] [else (cons (first lst)(evens (rest (rest lst))))])) ;;Tests: (check-expect (evens empty) empty) (check-expect (evens '(0)) '(0)) (check-expect (evens '(0 1)) '(0)) (check-expect (evens '(0 1 2 3 4 5 6)) '(0 2 4 6)) ;;odds: (listof any) -> (listof any)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 10/21/2010 for the course CS 116 taught by Professor T.vasiga during the Fall '09 term at Waterloo.

### Page1 / 2

a3q4 - ; The first three lines of this file were inserted...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online