Groups | Search | Server Info | Login | Register
Groups > comp.lang.scheme > #6500
| From | "B. Pym" <Nobody447095@here-nor-there.org> |
|---|---|
| Newsgroups | comp.lang.lisp, comp.lang.scheme |
| Subject | Re: Exercises, chap. 3, Graham |
| Date | 2025-07-11 00:42 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <104pmls$14ona$1@dont-email.me> (permalink) |
Cross-posted to 2 groups.
Alan Crowe wrote:
> (defun occurrences-CL-condensed (list)
> (sort (loop for x in (remove-duplicates list)
> collect (cons x (count x list)))
> #'> :key #'cdr))
Gauche Scheme
(define (occurrences-GS-condensed List)
(sort
(map
(^x (cons x (count (pa$ equal? x) List)))
(delete-duplicates List))
> cdr))
Testing.
(occurrences-GS-condensed '(a b c d e f b c d e b c d))
===>
((b . 3) (c . 3) (d . 3) (e . 2) (a . 1) (f . 1))
Shorter yet.
(define (occurrences-GS-condensed List)
(sort
(map
(^x (cons x (count (is x) List)))
(delete-duplicates List))
> cdr))
Given:
(define is
(case-lambda
[(x) (lambda(y) (equal? y x))]
[(pred x) (lambda(y) (pred y x))]
[(pred key x) (lambda(y) (pred (key y) x))]))
Back to comp.lang.scheme | Previous | Next | Find similar
Re: Exercises, chap. 3, Graham "B. Pym" <Nobody447095@here-nor-there.org> - 2025-07-11 00:42 +0000
csiph-web