Re: group-by: question
Shu-Hung You <[email protected]>
| Newsgroups | gmane.comp.lang.racket.user,gmane.lisp.scheme.plt |
|---|---|
| Message-ID | <CAMTzy+bdnFdKY3d5HRKDQLSwgH_EntYiUd_Lfp2HcvG__+4NoQ@mail.gmail.com> |
It can always be subsumed by `same?`, but can express the intention
better when the supplied list has some internal structure, e.g. an
association list:
(group-by car
'(("A" . a) ("b" . b) ("C" . c) ("a" . a))
string-ci=?)
In this example, `car` extracts the key from the association list and
we wish to group the list by the key, case insensitively.
On Fri, Jun 22, 2018 at 2:05 PM, Jos Koot <[email protected]> wrote:
> Hi,
> I don't understand the functionality of argument [key] in procedure
> [group-by].
> If I understand it correctly,
> this functionality always can be incorporated in argument [same?]:
>
>
> (group-by
> (lambda (x) (modulo x 3))
> '(1 2 1 2 54 2 5 43 7 2 643 1 2 0))
>
> (group-by identity
> '(1 2 1 2 54 2 5 43 7 2 643 1 2 0)
> (λ (x y) (zero? (modulo (- x y) 3))))
>
> An explanation of the functionality of argument [key] would be very welcome.
>
> Thanks, Jos
>
> PS.
> Today I came across procedure [group-by].
> Up to today I used my own version of [group-by]
> without [key]-argument (called [eqv-classes]).
> In order to avoid duplicate code,
> from now on use [group-by]
> but always with [key] = [identity].
> Jos
>
> --
> 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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
> 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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
For more options, visit https://groups.google.com/d/optout.