Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Real Users are afraid they'll break the machine -- but they're never afraid to break your face.


devel / comp.lang.lisp / .Re: How to improve my summarizing code

SubjectAuthor
o .Re: How to improve my summarizing codeRobert L.

1
.Re: How to improve my summarizing code

<t0kjnq$1m5a$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!W3tGPiuqVkNEMj0crCqmNQ.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: .Re: How to improve my summarizing code
Date: Sun, 13 Mar 2022 11:15:08 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <t0kjnq$1m5a$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="55466"; posting-host="W3tGPiuqVkNEMj0crCqmNQ.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. - Sun, 13 Mar 2022 11:15 UTC

Wade Humeniuk wrote:

> Yeah, but I do not worry about it, much, at the beginning. Here
> is another, it seems easier to think in the morning
>
> (defun summarize (list)
> (let ((summary nil))
> (map nil (lambda (elt)
> (let ((sum (find (first elt) summary :test #'eql :key #'first)))
> (if sum
> (incf (second sum) (second elt))
> (push elt summary))))
> list)
> summary))
>
> and its loop version
>
> (defun summarize (list)
> (loop with summary = nil
> for elt in list
> for sum = (find (first elt) summary :test #'eql :key #'first)
> if sum do (incf (second sum) (second elt))
> else do (push elt summary)
> finally (return summary)))
>
> CL-USER 2 > (summarize '((c 7) (a 1) (a 3) (b 1) (b 10) (b 100)))
> ((B 111) (A 4) (C 7))

Gauche Scheme:

(use srfi-1) ;; unzip2

(define (summarize alist)
(define (kons k v a)
(cons
(cons k (+ v (assoc-ref a k 0)))
(alist-delete k a)))
(apply fold
kons
'()
(values->list (unzip2 alist))))

(summarize '((c 7) (a 1) (a 3) (b 1) (b 10) (b 100)))

===>
((b . 111) (a . 4) (c . 7))


devel / comp.lang.lisp / .Re: How to improve my summarizing code

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor