This document provides steps for structurally recursive functions over list data:
1) Start with the basic template for recursion over lists
2) Wrap the recursive function in a local to enable trampolining
3) Add an accumulator parameter to the inner recursive function to pass recursive values
This document provides steps for structurally recursive functions over list data:
1) Start with the basic template for recursion over lists
2) Wrap the recursive function in a local to enable trampolining
3) Add an accumulator parameter to the inner recursive function to pass recursive values
This document provides steps for structurally recursive functions over list data:
1) Start with the basic template for recursion over lists
2) Wrap the recursive function in a local to enable trampolining
3) Add an accumulator parameter to the inner recursive function to pass recursive values
Steps 1:Structural recursion template for (listof X)
1. Structural recursion template for (listof X)
(define (fn-for-lox lox) 2. Wrapping in local with trampoline 3. Adding accumulator parameter (cond [(empty? lox) (...)] As argument to inner function [else After every … (... (first lox) Any call to the inner function (fn-for-lox (rest lox)))])) Acc. value in the trampoline as … 4. Specify the type, invariant, and examples of acc. 5. Complete the function 2:Wrapping in local with trampoline Don’t forget to Initialize, update, exploit (define (outer-fn lox0) the accumulator (local [(define (fn-for-lox lox) (cond [(empty? lox) (...)] [else (... (first lox) (fn-for-lox (rest lox)))]))] (fn-for-lox lox0)))