[plt-scheme] HTDP Section 18 Pragmatics of local, Part 2

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Apr 22 17:58:27 EDT 2009

The coding step of the design recipe asks you to reflect on the  
following questions:

  1. what's the answer in the non-recursive cases? examples tell you.
  2. what's the value of the template expressions in the recursive  
	-- one of the template expressions is (last-occurrence s (rest  
	-- did you answer the question for that one?

	-- another expression is (first alostars)?
	-- did you answer the question for that?
  3. can you think of a function/expression that combines the answers  
of questions 2 into the desired answer for the funciton you are  

If you have absorbed the design recipe, you can answer the questions  
for yourself and you will never forget.

-- Matthias

On Apr 22, 2009, at 4:18 PM, Emeka wrote:

> The below code is an example from the HTDP (no yelling ). Could  
> someone explain the highlighted part in detail?  I want something  
> that is detailed enough because I understand the general idea.
> ;; last-occurrence : symbol list-of-star  ->  star or false
> ;; to find the last star record in alostars that contains s in name  
> field
> (define (last-occurrence s alostars)
> (cond
> [(empty? alostars) false]
> [else (local ((define r (last-occurrence s (rest alostars))))
> (cond
> [(star? r) r]
> [(symbol=? (star-name (first alostars)) s) (first alostars)]
> [else false]))]))
> Thanks in advance.
> Regards,
> Emeka
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.