...
Code Block |
---|
(define (f_fwd loa) (cond [(empty? loa) base] [(cons? loa) (local [(define (helper acc loa2) (cond [(empty? loa2) acc] [(cons? loa2) (helper (... (first loa2)...acc...) (rest loa2))]))] (helper base loa))])) |
But to make that leap requires 2 conditions to be true:
- The "..."'s in both the helper and the outer cons? clause must be identical.
- "base" must represent a value, as opposed to something such as a exception.
For instance, the finding the largest element in a list follows only the first template:
Code Block |
---|
(define (get_largest lon)
(cond
[(empty? lon) (error "no largest in an empty list")]
[(cons? lon)
(local
[(define (helper acc lon2)
(cond
[(empty? lon2) acc]
[(cons? lon2) (helper (if (> (first lon2) acc) (first lon2) acc) (rest lon2))]))]
(helper (first lon) (rest lon)))])) |