[plt-scheme] HTDP Section 18 Pragmatics of local, Part 2
Emeka,
When you define a structure, you get several functions associated with
the structure.
In section 18 you have the following definition:
(define-struct star (name instrument))
Based on this definition, you get observers that extract the
components of the function (i.e. star-name and star-instrument). You
also get a function, star?, to determine it its input is a star
structure. For example, (star? (make-star 'Bach 'violin)) returns true
and (star? 4) returns fasle.
On Wed, Apr 22, 2009 at 4:18 PM, Emeka <emekamicro at gmail.com> 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
>
>
--
Cheers,
Marco