Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: rearranging the properties in a property list

54 views
Skip to first unread message

WJ

unread,
Mar 19, 2012, 8:06:52 AM3/19/12
to
Barry Margolin wrote:

> > I have a list with contains property lists with the properties:
> > :date
> > :personal
> > :utilities
> > :dogs
>
> > This is the sequence I would prefer the properties to be in the list.
> > When new lists are added, this is the sequence, but for old lists this
> > is not the case. Is there a way to rearrange the properties in the
> > property lists in my list?
>
> > The reason I want this, is that the saved list is more human readable.
>
> (defun canonicalist-plist (plist)
> (flet ((get-prop (prop)
> (list prop (getf plist prop))))
> (mapcan #'get-prop '(:date :personal :utilities :dogs))))
>
> This assumes there are no other properties in the plist that you need to
> retain.

Clojure:

(defn normalize-plist [plist]
(let [tbl (apply hash-map plist)]
(mapcat #(list % (tbl %))
'(:date :personal :utilities :dogs))))

WJ

unread,
Apr 15, 2013, 1:49:49 AM4/15/13
to
WJ wrote:

> Barry Margolin wrote:
>
> > > I have a list with contains property lists with the properties:
> > > :date
> > > :personal
> > > :utilities
> > > :dogs
> >
> > > This is the sequence I would prefer the properties to be in the list.
> > > When new lists are added, this is the sequence, but for old lists this
> > > is not the case. Is there a way to rearrange the properties in the
> > > property lists in my list?
> >
> > > The reason I want this, is that the saved list is more human readable.
> >
> > (defun canonicalist-plist (plist)
> > (flet ((get-prop (prop)
> > (list prop (getf plist prop))))
> > (mapcan #'get-prop '(:date :personal :utilities :dogs))))
> >
> > This assumes there are no other properties in the plist that you need to
> > retain.

Instead of CL, tCL.

namespace path {tcl::mathop tcl::mathfunc}

proc compare args {
- {*}[lmap x $args {lsearch {:date :personal :utilities :dogs} $x}]}

proc norm_plist plist {lsort -stride 2 -command compare $plist}


norm_plist {:dogs 2 :date "2012-08-09" :personal foo :utilities 3}
==>
:date 2012-08-09 :personal foo :utilities 3 :dogs 2

WJ

unread,
Dec 16, 2013, 5:51:17 AM12/16/13
to
WJ wrote:

> WJ wrote:
>
> > Barry Margolin wrote:
> >
> > > > I have a list with contains property lists with the properties:
> > > > :date
> > > > :personal
> > > > :utilities
> > > > :dogs
> > >
> > > > This is the sequence I would prefer the properties to be in the list.
> > > > When new lists are added, this is the sequence, but for old lists this
> > > > is not the case. Is there a way to rearrange the properties in the
> > > > property lists in my list?
> > >
> > > > The reason I want this, is that the saved list is more human readable.
> > >
> > > (defun canonicalist-plist (plist)
> > > (flet ((get-prop (prop)
> > > (list prop (getf plist prop))))
> > > (mapcan #'get-prop '(:date :personal :utilities :dogs))))
> > >
> > > This assumes there are no other properties in the plist that you need to
> > > retain.

Clojure:

(defn canonicalist-plist [plist]
(let [table (apply hash-map plist)]
(mapcat #(find table %) [:date :personal :utilities :dogs])))

WJ

unread,
Jun 21, 2014, 12:06:35 AM6/21/14
to
WJ wrote:

> WJ wrote:
>
> > Barry Margolin wrote:
> >
> > > > I have a list with contains property lists with the properties:
> > > > :date
> > > > :personal
> > > > :utilities
> > > > :dogs
> > >
> > > > This is the sequence I would prefer the properties to be in the list.
> > > > When new lists are added, this is the sequence, but for old lists this
> > > > is not the case. Is there a way to rearrange the properties in the
> > > > property lists in my list?
> > >
> > > > The reason I want this, is that the saved list is more human readable.
> > >
> > > (defun canonicalist-plist (plist)
> > > (flet ((get-prop (prop)
> > > (list prop (getf plist prop))))
> > > (mapcan #'get-prop '(:date :personal :utilities :dogs))))
> > >
> > > This assumes there are no other properties in the plist that you need to
> > > retain.
>

elisp:

(require 'dash)

(defun canonicalist-plist (plist)
(--mapcat
(list it (plist-get plist it))
'(:date :personal :utilities :dogs)))

(canonicalist-plist
'(:dogs 2 :date "2012-08-09" :personal foo :utilities 3))

===> (:date "2012-08-09" :personal foo :utilities 3 :dogs 2)

WJ

unread,
Mar 25, 2015, 12:07:14 AM3/25/15
to
WJ wrote:

> Barry Margolin wrote:
>
> > > I have a list with contains property lists with the properties:
> > > :date
> > > :personal
> > > :utilities
> > > :dogs
> >
> > > This is the sequence I would prefer the properties to be in the list.
> > > When new lists are added, this is the sequence, but for old lists this
> > > is not the case. Is there a way to rearrange the properties in the
> > > property lists in my list?
> >
> > > The reason I want this, is that the saved list is more human readable.
> >
> > (defun canonicalist-plist (plist)
> > (flet ((get-prop (prop)
> > (list prop (getf plist prop))))
> > (mapcan #'get-prop '(:date :personal :utilities :dogs))))
> >
> > This assumes there are no other properties in the plist that you need to
> > retain.

Gauche Scheme:

(define (standardize-plist plist)
(append-map
(^x (list x (get-keyword x plist)))
0 new messages