Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Due to lack of disk space, this fortune database has been discontinued.


devel / comp.lang.lisp / .re: need help with data structure problem

SubjectAuthor
o .re: need help with data structure problemRobert L.

1
.re: need help with data structure problem

<suv5ic$tr1$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!iioOyTa3q2B0LcgUrwsJUg.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: .re: need help with data structure problem
Date: Mon, 21 Feb 2022 04:48:13 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <suv5ic$tr1$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="30561"; posting-host="iioOyTa3q2B0LcgUrwsJUg.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. - Mon, 21 Feb 2022 04:48 UTC

> hi, I need to write a function (join_similar expr) where expr is
> adata structure with the following format ( (x1 y1) (x2 y2) (x3 y3)...
> (xn yn)),
>
> join_similar will return an expression like ( (x1 y1 y2) (x3 y3) ...)
> when x1=x2
>
> for instance:
> *(join_similar '((3 4) (7 5) (3 6) (7 8) (3 9) (0 1))
>
> would return:
> ((3 4 6 9) (7 5 8) (0 1))

Kenny Tilton wrote:

> Lieven Marchand wrote:
> > CL-USER 9 > (defun join-similar (list)
> > (loop with ht = (make-hash-table)
> > for (first second) in list
> > do
> > (pushnew second (gethash first ht nil))
> > finally (return (loop for first being each hash-key in ht using (hash-value rest) collect (cons first rest)))))
> > JOIN-SIMILAR
>
> > Isn't LOOP beautiful? <g,d&r>
>
> <g> No...
>
> (defun join-similar (pairs &aux result)
> (dolist (pair pairs (nreverse result))
> (nconc (or (assoc (first pair) result)
> (first (push (list (first pair)) result)))
> (list (second pair)))))

Gauche Scheme or Racket:

;; Racket needs these SRFIs:
(require srfi/1)
(require srfi/26)

(define (amerge kv a)
(cons
(cond ((assoc (car kv) a) => (cut append <> (cdr kv)))
(else kv))
(alist-delete (car kv) a)))

(define (join-similar pairs) (fold amerge '() pairs))

(join-similar '((3 4) (7 5) (3 6) (7 8) (3 9) (0 1)))
===>
'((0 1) (3 4 6 9) (7 5 8))


devel / comp.lang.lisp / .re: need help with data structure problem

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor