Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

BASIC is the Computer Science equivalent of `Scientific Creationism'.


devel / comp.lang.lisp / .Re: ANSI Common Lisp, Page 56, Problem 3

SubjectAuthor
o .Re: ANSI Common Lisp, Page 56, Problem 3Robert L.

1
.Re: ANSI Common Lisp, Page 56, Problem 3

<svr87f$1919$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16945&group=comp.lang.lisp#16945

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!5nyZhpkiNfgu6UGE4qaSHw.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: .Re: ANSI Common Lisp, Page 56, Problem 3
Date: Thu, 3 Mar 2022 20:25:20 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <svr87f$1919$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="42025"; posting-host="5nyZhpkiNfgu6UGE4qaSHw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: XanaNews/1.18.1.6
X-Notice: Filtered by postfilter v. 0.9.2
 by: Robert L. - Thu, 3 Mar 2022 20:25 UTC

> On 2016-08-30, Steve Graham <solitary.wanderer52@gmail.com> wrote:
> > The problem states:
> >
> > Define a function that takes a list and returns a list indicating the
> > number of times each (eql) element appears, sorted from most common
> > element to least common
>
> $ txr
> This is the TXR Lisp interactive listener of TXR 147.
> Use the :quit command or type Ctrl-D on empty line to exit.
> 1> [group-by identity '(a a b a c b c c a a d e)]
> #H(() (e (e)) (d (d)) (a (a a a a a)) (c (c c c)) (b (b b)))
> 2> [hash-update [group-by identity '(a a b a c b c c a a d e)] length]
> #H(() (e 1) (d 1) (a 5) (c 3) (b 2))
> 3> (hash-pairs [hash-update [group-by identity '(a a b a c b c c a a d
> e)] length])
> ((e 1) (d 1) (a 5) (c 3) (b 2))
> 4> [sort (hash-pairs [hash-update [group-by identity '(a a b a c b c c
> a a d e)] length]) > second]
> ((a 5) (c 3) (b 2) (d 1) (e 1))

Without using a hash-table or mutation.

Gauche Scheme:

(use srfi-1) ;; lset-difference

(define (update-alist alist item)
(define found (assoc item alist))
(if found
(cons (list item (+ 1 (cadr found)))
(lset-difference (lambda (a b) (equal? (car a) b))
alist (list item)))
(cons (list item 1) alist)))

(define (foo the-list)
(let go ((xs the-list) (counts '()))
(if (null? xs)
(sort counts > cadr)
(go (cdr xs) (update-alist counts (car xs))))))

(foo '(a a b a c b c c a a d e))
===>
((a 5) (c 3) (b 2) (e 1) (d 1))


devel / comp.lang.lisp / .Re: ANSI Common Lisp, Page 56, Problem 3

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor