[racket] xml/plist plist-dict

21 views
Skip to first unread message

Steve Byan

unread,
May 31, 2012, 5:09:57 PM5/31/12
to us...@racket-lang.org
I've finally found the time and motivation to start exploring racket in earnest. I'm diving right in by trying to edit the preferences in my Mac OS X Mail.app mail client to set all my mailboxes to sort in descending order. This involves scanning over the xml in all the Info.plist files scattered throughout my ~/Library/Mail/V2/Mailboxes directory tree, finding the ones with the "SortedDescending" property set to "NO", and re-writing them with "SortedDescending" set to "YES".

Many thanks to the fine Racket developers; I'm finding the documentation surprisingly useful for "just diving in". (The last LISP I wrote in earnest was before Scheme had been invented, back in 6.011 in 1973.) Thanks also to the developer of the xml/plist library; I didn't expect to have something already in the library that parses Apple's plist xml DTD. (BTW, avoiding xpath and xslt was the primary motivator for trying to write this in Racket; at this point, I only have a limited number of brain cells to spend, and don't want to waste them on learning that nonsense.)

However, I would appreciate a pointer. I've got "find-files" working to produce a list of all my Info.plist files, and the "for" list-comprehension iterating over "find-files" result, and "call-with-input-file" working with "read-plist" to suck in the XML and produce a "plist-dict".

But, I'm at something of a loss to understand what to do with a plist-dict. Is there a way to convert between a plist-dict and a real dictionary and vice-versa? I'd like to query the existence of the property key, get its value, and either mutate it by setting a new value or copy it with a new value for the key. I see the grammar for plist-dicts in the docs, but my instinct tells me that there's a better way to deal with them than by writing functions based on the grammar to implement the dictionary-like behavior that I seek.

Best regards,
-Steve

--
Steve Byan <stev...@me.com>
Littleton, MA 01460



--
Steve Byan <stev...@me.com>
Littleton, MA 01460




____________________
Racket Users list:
http://lists.racket-lang.org/users

Jay McCarthy

unread,
May 31, 2012, 5:27:10 PM5/31/12
to Steve Byan, us...@racket-lang.org
Tell me if this works well and I'll commit it:

https://github.com/jeapostrophe/exp/blob/master/plist-dict.rkt

One problem could be that it doesn't preserve the order of the
original plist dict entries. I could switch it to use an alist and the
dict interface, if that IS a problem.

Jay

--
Jay McCarthy <j...@cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93

Steve Byan

unread,
May 31, 2012, 5:52:52 PM5/31/12
to Jay McCarthy, us...@racket-lang.org

On May 31, 2012, at 5:27 PM, Jay McCarthy wrote:

> Tell me if this works well and I'll commit it:
>
> https://github.com/jeapostrophe/exp/blob/master/plist-dict.rkt

Thanks, I'll give it a try.

> One problem could be that it doesn't preserve the order of the
> original plist dict entries. I could switch it to use an alist and the
> dict interface, if that IS a problem.

I believe plists are supposed to be order-independent, but I'm worried about triggering latent bugs if I switch the order. (Especially so because I'm mucking with my mailer.) I hate to impose but an alist implementation would let me sleep easier. Maybe I can fake one myself after I look at your code.

Best regards,
-Steve

--
Steve Byan <stev...@me.com>
Littleton, MA 01460




Jay McCarthy

unread,
Jun 1, 2012, 7:44:43 PM6/1/12
to Steve Byan, us...@racket-lang.org
I just pushed the alist version

Jay

--

Jay McCarthy <j...@cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93

____________________

Steve Byan

unread,
Jun 6, 2012, 4:58:54 PM6/6/12
to Jay McCarthy, us...@racket-lang.org

On Jun 1, 2012, at 7:44 PM, Jay McCarthy wrote:

> I just pushed the alist version

Thanks, it works great! Very interesting code, I'll have to read up on match and friends. Looks like you basically took the grammar from the plist-dict documentation and wrote a recursive-descent parser?

On the broader front, while read-plist works great, write-plist unfortunately writes a slightly older version of the plist DTD (0.9 rather than 1.0), and doesn't pretty-print the xml output. So now I'm off to try to improve write-plist.

I must say, I'm having great fun with Racket.

Matthias Felleisen

unread,
Jun 6, 2012, 5:01:29 PM6/6/12
to Steve Byan, Jay McCarthy, us...@racket-lang.org

On Jun 6, 2012, at 4:58 PM, Steve Byan wrote:

> I'm having great fun with Racket.


We all do :-)
Reply all
Reply to author
Forward
0 new messages