Question: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( define ( filter - credits - course - num c course - num num - credits ) ( local [ ( define (

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (filter-credits-course-num c course-num num-credits)
(local [(define (fn-for-course c)
(cond
[(and (>=(course-number c) course-num)
(>=(course-credits c) num-credits)
(empty?(course-dependents c)))
(list (course-number c))]))
; (fn-for-loc (course-dependents c)))
(define (fn-for-loc loc)
(cond [(empty? loc) empty]
[else
(append (fn-for-course (first loc))
(fn-for-loc (rest loc)))]))]
;define helper function is a tail recursive function that use an accumulator acc to collect
;elements. The helper function processes each element in the list, updating the accumulator
;as necessary, and the recursive call is the last operation, making it tail-recursive.
(define (filter-helper c acc)
(cond
[(empty? c) acc]; return the accumulated result.
[(course? c)(cons (fn-for-course c) acc)] ; append new acc to
[(not (empty?(course-dependents c)))(filter-helper (rest (fn-for-loc (course-dependents c))))
(cons (first (fn-for-loc (course-dependents c))) acc)]; add to accumulator
[else (filter-helper (rest (fn-for-loc (course-dependents c))) acc)])) ;skip element
(filter-helper c '()))); the above coding has bug, it cannot return course dependents are list of course, what went wrong?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!