equiv

# equiv - (cond [(symbol? c) 0] [else (+ a b c)])])) ;;Tests:

This preview shows page 1. 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-beginner-reader.ss" "lang")((modname equiv) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ()))) ;; Ru Wang 20319247 CS135 Sect 001 Tut 108 ; ;;Question 2: ; ;;my-weird-fun: number expression expression -> number ; ;;purpose: to create a functionally equivalent function as weird-fun from question 1. 1 ;; Examples: (my-weird-fun 1 2 3) => 6 ;; (my-weird-fun 'symbol 'symbol 'symbol) => 0 ;; (my-weird-fun 2 3 'symbol) => 0 ;; (my-weird-fun 'symbol 2 3) => Error: + can only add numerical values. ; ;; Definition: (define (my-weird-fun a b c) (cond [(symbol? b) 0] [else
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: (cond [(symbol? c) 0] [else (+ a b c)])])) ;;Tests: (check-expect(my-weird-fun 1 2 3)6) (check-expect(my-weird-fun 'symbol 'symbol 'symbol)0) (check-expect(my-weird-fun 2 3 'symbol) 0) ;;(check-expect(my-weird-fun 'symbol 2 3)Error: + can only add numbers) ; ;;my-strange: number number -&gt; number ; ;;purpose: to create a functionally equivalent function as strange from question 1. ; ;; Examples: (my-strange 5 5) =&gt; 0 ;; (my-strange 8 3) =&gt; 0 ;; (my-strange 'sarah 'palin) =&gt; error: my-strange only takes numbers as arguments a ;;Definition: (define (my-strange a b) (cond [(and (number? a)(number? b)) 0])) ;;Tests: (check-expect(my-strange 5 5) 0) (check-expect(my-strange 8 3) 0) ;;(check-expect(my-strange 'sarah 'palin)Error: my-strange only takes numbers as arguments)...
View Full Document

## This note was uploaded on 10/21/2010 for the course CS 135 taught by Professor Vasiga during the Fall '07 term at Waterloo.

Ask a homework question - tutors are online