Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

If it wasn't for Newton, we wouldn't have to eat bruised apples.


devel / comp.lang.lisp / .Re: Inverting alists -- *NOT* a homework assignment!!

SubjectAuthor
o .Re: Inverting alists -- *NOT* a homework assignment!!Robert L.

1
.Re: Inverting alists -- *NOT* a homework assignment!!

<t27kin$1b6r$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!lNWn9cxTR/GpcgzEu9WJbg.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: .Re: Inverting alists -- *NOT* a homework assignment!!
Date: Fri, 1 Apr 2022 19:42:18 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <t27kin$1b6r$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="44251"; posting-host="lNWn9cxTR/GpcgzEu9WJbg.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. - Fri, 1 Apr 2022 19:42 UTC

Christopher N. Vogt wrote:

> > ;; Hi. I would like to invert an alist of the form ;; ;; ((reference-1
> > referent-a referent-b...) (reference-2 referent-c ...)...) ;; ;; to
> > another alist of the form ;; ;; ((referent-a reference-1) (referent-b
> > reference-1) ;; (referent-c reference-2) ...) ;; ;; I have gotten
> > something to work but it's so stupefyingly *UGLY* that I ;; just know
> > someone out there can demonstrate a more better beautiful ;; elegant
> > means of achieving the same result. ;; ;; [ I'm working in emacs-lisp
> > with the 'cl' package, so the code below ;; ought to be reasonably close
> > to Common Lisp...] ;; ;; ;; Mind you, I am teaching myself lisp and THIS

.....

> I'd do it something like this:
> (defun invert-alist (alist)
> (loop for list in test
> for reference = (first list)
> appending (loop for referent in (cdr list)
> collect (list referent reference))))

Gauche Scheme or Racket:

;; cut for Racket
(require srfi/26)

(define (invert-alist alist)
(append-map
(lambda (xs) (map (cut list <> (car xs)) (cdr xs)))
alist))

(invert-alist '((a 0 2) (b 3 5 7)))
===>
((0 a) (2 a) (3 b) (5 b) (7 b))

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor