Re: Printing an alist of plists with cons format
Heime <[email protected]>
| Newsgroups | gmane.emacs.help |
|---|---|
| Message-ID | <Lc7Vivucr0IsehD20nQaSEjxsZdQGeMS_X1jFeg5420fUNafLBtxn1PtfDjQ1KiFSl1mGDzh4yLkPVu7-9L5f_segYIfuP7ZBMaB_eUTYcc=@protonmail.com> |
On Tuesday, March 24th, 2026 at 1:39 AM, Stefan Monnier via Users list for the GNU Emacs text editor <[email protected]> wrote: > >> ((: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))))) > > I disagree. The first above is an "alist of plists" while the > alternative you propose would be an "alist of (singleton) lists of > plists". > E.g. `(alist-get :in ...)` would return > > (:10pt 720 :pt 72 :mm 25.4 :cm 2.54 :ft 0.083333) > > for the first and > > ((:10pt 720 :pt 72 :mm 25.4 :cm 2.54 :ft 0.083333)) > > for the second > > === Stefan I am still failing to transfer the level-two plist as an entity as the second element of each cons cell. (defun mpl-plist-to-alist (plist) "Convert a nested two-level plist (:u1 plist1 :u2 plist2 ...) to an alist at top-level '((u1 . plist1) (u2 . plist2) ...)." (let ( (alist nil) (tail plist)) (while tail (let ( (unit (car tail)) (mltp (cadr tail)) ) (push (cons unit mltp) alist) (setq tail (cddr tail)))) (nreverse alist)))