reset password
Author Message
Amedrano
Posts: 80
Posted 18:27 Oct 19, 2015 |
(define (my-reverse the-list)
  ;; The function my-reverse-aux is defined locally within my-reverse
  (define (my-reverse-aux list-in accumulator)
    (if (empty? list-in) accumulator
        (let* ([fst (first list-in)]
               [rst (rest list-in)]
               [new-accum (cons fst accumulator)])
          (my-reverse-aux rst new-accum))))   
    ;; Execution of my-reverse starts here.
    (my-reverse-aux the-list empty))

How does "let*" work?

waaffles
Posts: 16
Posted 18:30 Oct 19, 2015 |

Let is just a way of defining variables within a local scope, so everything from the left paren of (let* all the way over to the right paren in new-accuum))) can use the variables it defined. After that line you would no longer have access t the fst, rst, and new-accum variables

Amedrano
Posts: 80
Posted 18:57 Oct 19, 2015 |

Got it THANKS

rabbott
Posts: 1649
Posted 09:21 Oct 20, 2015 |

Good answer. Nicely asked question with the blue highlighting. Makes it clear what you are asking about. The actual let* expression continues through the next line as the previous comment indicates. That's where rst and new-accum are used. 

 

Last edited by rabbott at 09:22 Oct 20, 2015.