I don't know whether there's an advantage or not, but I can say that the
behavior of assoc is inherited from Scheme and other Lisps.

I usually want the behavior you describe, so I often use dict-ref with
dealing with association lists.

-Jon


On Wed, Feb 10, 2016 at 10:55 AM, Brian Adkins <lojicdot...@gmail.com>
wrote:

> Is there an advantage to having assoc return the associated list vs. the
> tail of the associated list? Wouldn't it be better for it to behave more
> like hash-ref ? Do folks typically just define their own function such as
> the following ?
>
> (define daynums (map list
>                      '(sunday monday tuesday wednesday thursday friday
> saturday)
>                      (range 7)))
>
> (define (aref list key)
>   (cadr (assoc key list)))
>
> (aref daynums 'wednesday)  -> 3
>
> Ruby's Array#assoc also returns the entire list, so I suppose this is just
> a historical artifact, but off the top of my head, I can't recall ever
> wanting the entire list since I already have the key I'm searching for.
>
> Brian
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to