Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could you please fill out this scheme? Thanks so much. IN SCHEME ;;; predicates: list? null? eq? equal? ;;; quote ;;; car cdr caddr ;;;

Could you please fill out this scheme? Thanks so much. IN SCHEME;;; predicates: list? null? eq? equal?;;; quote;;; car cdr caddr;;; cons list append;;; length(newline)(display (cons 0 '(1 2 3)))(newline)(display (cons '(a b) '(1 2 3)))(newline)(display (cons (+ 10 20) '(1 2 3)))(newline)(display (list '(a) '(b c d)))(newline)(display (append '(a) '(b c d)))(newline)(display (cdadr '((1 2) (3 4) (5 6))))(newline)(display (list (+ 2 3) 0))(newline)(display (list '(+ 2 3) 0))(newline)(display (cons (car '(1 2 3)) (list 'a 'b 'c)))(newline)(display (append '(1 2 3) (list 'a 'b 'c)))(newline)(define (length lst) (cond ((null? lst) 0) ((list? lst) (+ 1 (length (cdr lst)))) (else 0) ))(define (maxelt lst) (if (null? (cdr lst)) (car lst) (max (car lst) (maxelt (cdr lst)))))(define (minelt lst) (if (= (length lst) 1) (car lst) (min (car lst) (minelt (cdr lst)))))(define (numzeros lst) ; fill this in 0)(newline)(display \"Testing numzeros\")(newline)(display (numzeros `()))(newline) ; expect 0(display (numzeros `(0)))(newline) ; expect 1(display (numzeros `(0 0)))(newline) ; expect 2(display (numzeros `(1 0 1 0 1 0)))(newline) ; expect 3(display (numzeros `(1 1 1 1)))(newline) ; expect 0(define (randlist len) (if (= len 0) '() (cons (random 100) (randlist (- len 1)) ) ))(define (allbutlast lst) ; complete. return original list, but without the last element ; lst should never be empty (no need to check for that) '() )(newline)(display \"Testing allbutlast\")(newline)(display (allbutlast '(1 2 3 4 5)))(newline) ; expect (1 2 3 4)(display (allbutlast '(1)))(newline) ; expect ()(define (ismember atm lst) (cond ((null? lst) #f) ((equal? atm (car lst)) #t) (else (ismember atm (cdr lst))) ))(define (odds lst) (cond ((null? lst) '()) ((odd? (car lst)) (cons (car lst) (odds (cdr lst)))) (else (odds (cdr lst))) ))(define (minandmax lst) ; fill this in. return (min, max) '(0 0))(newline)(display \"Testing minandmax\")(newline)(display (minandmax `( 1 2 3 4 5)))(newline) ; (1 5)(display (minandmax `( 5 4 3 2 1)))(newline) ; (1 5)(display (minandmax `( 5)))(newline) ; (5 5)(display (minandmax `( 5 -5 3 -3 2 -2 1 -1 0)))(newline) ; (-5 5)(define (zip lst1 lst2) ; fill this in; input is two simple lists of same length: (1 2 3 4) (a b c d); returns ((1 a) (2 b) (3 c) (4 d)) '())(newline)(display \"Testing zip\")(newline)(display (zip '(1 2 3 4) '(a b c d)))(newline)(define (remove v lst) (cond ((null? lst) '() ) ((= v (car lst)) (cdr lst)) (else (cons (car lst) (remove v (cdr lst)) ) ) ))(define (sort lst) (if (null? lst) '() (cons (minelt lst) (sort (remove (minelt lst) lst))) ))

Excepted Output:

(0 1 2 3)((a b) 1 2 3)(30 1 2 3)((a) (b c d))(a b c d)(4)(5 0)((+ 2 3) 0)(1 a b c)(1 2 3 a b c)Testing numzeros01230Testing allbutlast(1 2 3 4)()Testing minandmax(1 5)(1 5)(5 5)(-5 5)Testing zip((1 a) (2 b) (3 c) (4 d))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Elements Of Chemical Reaction Engineering

Authors: H. Fogler

6th Edition

013548622X, 978-0135486221

More Books

Students also viewed these Programming questions