Google 網路論壇不再支援新的 Usenet 貼文或訂閱項目,但過往內容仍可供查看。

Re: rearranging the properties in a property list

瀏覽次數:54 次
跳到第一則未讀訊息

WJ

未讀,
2012年3月19日 上午8:06:522012/3/19
收件者:
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

未讀,
2013年4月15日 凌晨1:49:492013/4/15
收件者:
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

未讀,
2013年12月16日 清晨5:51:172013/12/16
收件者:
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

未讀,
2014年6月21日 凌晨12:06:352014/6/21
收件者:
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

未讀,
2015年3月25日 凌晨12:07:142015/3/25
收件者:
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 則新訊息