Search Results
6/23/2025, 4:12:17 PM
I'm struggling on picrel. What I have is as such:
(define (cont-frac n d k)
(define (inv x) (/ 1 x))
(if (= k 1)
(n k)
(* (n (- k 1))
(inv (+ (d (- k 1))
(cont-frac n d (- k 1)))))))
Which... works. But it's omitting the final, terminating d.k at the end. I'm trying to implement this procedure precisely as directed, with no inner helper functions or inherited state. I'm trying to direct it entirely with control flow alone, in other words -- just raw computational, structural direction where control flow is a function of the shape of the problem rather than anything explicit (other than the unavoidable base case).
The problem here is that the final term, n.k / d.k, is the final term in the mathematical sequence but by necessity the not the base case because under these constraints I can't create an iterator variable or otherwise alter the function signature. Is it possible to insert this final term in front while maintaining my current constraints?
The iterative implementation is trivial, I know, but I'm trying to do it all by the book. Not looking for an answer or solution, just some food for thought.
(define (cont-frac n d k)
(define (inv x) (/ 1 x))
(if (= k 1)
(n k)
(* (n (- k 1))
(inv (+ (d (- k 1))
(cont-frac n d (- k 1)))))))
Which... works. But it's omitting the final, terminating d.k at the end. I'm trying to implement this procedure precisely as directed, with no inner helper functions or inherited state. I'm trying to direct it entirely with control flow alone, in other words -- just raw computational, structural direction where control flow is a function of the shape of the problem rather than anything explicit (other than the unavoidable base case).
The problem here is that the final term, n.k / d.k, is the final term in the mathematical sequence but by necessity the not the base case because under these constraints I can't create an iterator variable or otherwise alter the function signature. Is it possible to insert this final term in front while maintaining my current constraints?
The iterative implementation is trivial, I know, but I'm trying to do it all by the book. Not looking for an answer or solution, just some food for thought.
Page 1