Re: Printing an alist of plists with cons format

Stéphane Marks <[email protected]>
Newsgroups gmane.emacs.help
Message-ID <CAN+1Hbq0iuPDzXyorJV25m7+chb+vfDTA2Fao_XvDED0=L9dBA@mail.gmail.com>
On Mon, Mar 23, 2026 at 9:03 AM Heime <[email protected]> wrote:

>
>
>
>
> Sent with Proton Mail secure email.
>
> On Tuesday, March 24th, 2026 at 12:53 AM, Stéphane Marks <
> [email protected]> wrote:
>
> > On Mon, Mar 23, 2026 at 8:47 AM Heime <[email protected]>
> wrote:
> >
> > >
> > > Have made a two level plist
> > >
> > > (defvar mpl-length
> > >   '(:cm  (:10pt 283.46456 :pt 28.34646 :mm 10 :in 0.39370 :ft 0.03281)
> > >     :in  (:10pt 720 :pt 72 :mm 25.4 :cm 2.54 :ft 0.083333)
> > >     :ft  (:10pt 8640 :pt 864 :mm 304.8 :cm 30.48 :in 12)))
> > >
> > > And wanted to convert it to a different form: making the top-level
> plist
> > > into an alist.
> > >
> > > (defun mpl-plist-to-alist (plist)
> > >   "Convert a nested two-level plist (:u1 plist1 :u2 plist2 ...)
> > > to a plist nested in an alist '((u1 . plist1) (u2 . plist2) ...)."
> > >
> > >   (let (alist)
> > >     (while plist
> > >       (let ((unit   (pop plist))
> > >             (plist  (pop plist)))
> > >         (push (cons unit plist) alist)))
> > >     (nreverse alist)))
> > >
> > >
> > > This gives
> > >
> > > ((:cm :10pt 283.46456 :pt 28.34646 :mm 10 :in 0.3937 :ft 0.03281)
> > >  (:in :10pt 720 :pt 72 :mm 25.4 :cm 2.54 :ft 0.083333)
> > >  (:ft :10pt 8640 :pt 864 :mm 304.8 :cm 30.48 :in 12))
> > >
> >
> > That's a list of lists, not really an alist.  Try improving the code
> above
> > to produce this form:
> >
> > ((:cm (:10pt 283.46456 :pt 28.34646 :mm 10 :in 0.3937 :ft 0.03281))
> >  (:in (:10pt 720 :pt 72 :mm 25.4 :cm 2.54 :ft 0.083333))
> >  (:ft (:10pt 8640 :pt 864 :mm 304.8 :cm 30.48 :in 12)))))
>
> The difficulty seems to stem from (plist (pop plist))
>
> What should I use instead of pop to get the entire plist value?
>

Sorry for misleading, you can use your plain list as an alist.  The car of
each list element is the key.  Do this:

(alist-get :cm '((:cm :10pt 283.46456 :pt 28.34646 :mm 10 :in 0.3937 :ft
0.03281)
                 (:in :10pt 720 :pt 72 :mm 25.4 :cm 2.54 :ft 0.083333)
                 (:ft :10pt 8640 :pt 864 :mm 304.8 :cm 30.48 :in 12)))

(:10pt 283.46456 :pt 28.34646 :mm 10 :in 0.3937 :ft 0.03281)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.