Question: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( define ( filter - credits - course - num c course - num num - credits ) ( local [ ( define (
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
define filtercreditscoursenum c coursenum numcredits
local define fnforcourse c
cond
and coursenumber c coursenum
coursecredits c numcredits
emptycoursedependents c
list coursenumber c
; fnforloc coursedependents c
define fnforloc loc
cond empty loc empty
else
append fnforcourse first loc
fnforloc 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 tailrecursive.
define filterhelper c acc
cond
empty c acc; return the accumulated result.
course ccons fnforcourse c acc ; append new acc to
not emptycoursedependents cfilterhelper rest fnforloc coursedependents c
cons first fnforloc coursedependents c acc; add to accumulator
else filterhelper rest fnforloc coursedependents c acc ;skip element
filterhelper 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
