Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"I have just one word for you, my boy...plastics." -- from "The Graduate"


devel / comp.lang.lisp / :Re: duplicates

SubjectAuthor
o :Re: duplicatesRobert L.

1
:Re: duplicates

<t1gu4c$3gm$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!JnNdil0kAdh+kyjlcDAQpw.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: :Re: duplicates
Date: Thu, 24 Mar 2022 05:04:47 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <t1gu4c$3gm$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="3606"; posting-host="JnNdil0kAdh+kyjlcDAQpw.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, 24 Mar 2022 05:04 UTC

Pascal Costanza wrote:

> > There doesn't seem to be a way to return a list of duplicates of a
> > sequence in ANSI CL -- though there is a remove-duplicates. Is there a
> > reason for this? It would be handy if you could tell remove-duplicates
> > not to include any duplicated elements so you could do a set-
> > difference at the end to get a list of duplicates. Feel free to post
> > code to prove me wrong. Thanks!
>
> (loop
> with counts
> for element in list
> do (incf (getf counts element 0))
> finally (return
> (loop for (element count) on counts by #'cddr
> if (> count 1)
> collect element into duplicates
> else collect element into uniques
> finally (return (values uniques duplicates)))))

Shorter

;; For Gauche Scheme.
(use srfi-1) ;; alist-cons

or

;; For Racket.
(require srfi/1) ;; alist-cons alist-delete
(require srfi/8) ;; receive
(define assoc-ref dict-ref)

(define (alist-inc k a)
(alist-cons k (+ 1 (assoc-ref a k 0)) (alist-delete k a)))

(receive (uniq dup)
(partition
(& = 1 (cdr u))
(fold alist-inc '() '(c xo c f y f g g h z h h)))
(values (map car uniq) (map car dup)))

===>
(z y xo)
(h g f c)

Given:

(define-syntax &-aux
(syntax-rules (u v w & lambda quote)
[(_ () shadow (param ...) original)
(lambda (param ...) original)]
[(_ (u more ...) (x y ...) () original)
(&-aux original original (x) original)]
[(_ (v more ...) (x y ...) (a) original)
(&-aux original original (a x) original)]
[(_ (w more ...) (x y ...) (a b) original)
(&-aux () () (a b x) original)]
[(_ ((lambda x ...) more ...) (y z ...) params original)
(&-aux (more ...) (z ...) params original)]
[(_ ((& x ...) more ...) (y z ...) params original)
(&-aux (more ...) (z ...) params original)]
[(_ ((quote x ...) more ...) (y z ...) params original)
(&-aux (more ...) (z ...) params original)]
[(_ ('x more ...) (y z ...) params original)
(&-aux (more ...) (z ...) params original)]
[(_ ((s ...) more ...) (y z ...) params original)
(&-aux (s ... more ...) (s ... z ...) params original)]
[(_ (x more ...) (y z ...) params original)
(&-aux (more ...) (z ...) params original)]))
;; Lambda with anaphoric parameters u, v, and w.
(define-syntax &
(syntax-rules ()
[(& x ...)
(&-aux (x ...) (x ...) () (x ...))]))

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor