[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How to find a key in a property list?
From: |
Kalle Olavi Niemitalo |
Subject: |
How to find a key in a property list? |
Date: |
22 Mar 2001 11:03:28 +0200 |
Given a symbol SYM and a property name PROPNAME, how do I check
whether the symbol has that property? (get SYM PROPNAME) is no
good because the property might exist with a value of nil. (get*
SYM PROPNAME 'some-other-default) doesn't work either because the
value might happen to be some-other-default. I came up with
this:
(let* ((default-magic (list nil))
(value (get* sym propname default-magic)))
(eq value default-magic))
which is rather ugly but does the job. It also conses on each
invocation; if I avoid that by using a quoted constant, is it
possible that the compiler coalesces the constant with some other
constant and I get false positives? Which is more expensive, an
one-element list or an empty vector? Would an uninterned symbol
work better?
Writing this, I suddenly realized I could call get* with two
different defaults and compare the results. But this feels like
duplicating work.
Should I use an explicit loop? Can that be written legibly with
`loop'?
FYI, the package I'm writing implements documentation strings for
names of symbol, text and overlay properties.
- How to find a key in a property list?,
Kalle Olavi Niemitalo <=
- Message not available