help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Two questions about generalized variables


From: Eric Abrahamsen
Subject: Two questions about generalized variables
Date: Sun, 21 Feb 2016 13:16:43 +0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

I'm starting to learn a bit more about generalized variables, the gv-*
stuff and macroexpand-*, what have you, and I have two
practical/learning questions I hope someone can help me with.

The first is working with plists. It can be a pain setting many plist
entries at once, particularly when there's lots of surrounding
conditional code. You either have to keep doing

"(setq plist-var (plist-put plist-var ..."

Or else use a backquote template, but that's not always practical.

It looks like plist-get doesn't return a setf-able place. I was thinking
of making a "with-plist-slots" macro, and looking at the `with-slots'
macro as inspiration, but `with-slots' also requires setf-able places.
Is there a way to define something to make that work?


The second question is setting hashtable entries. Right now I have code
like this:

(setf (gethash uuid my-hashtable)
      (append (list (list 'thingone 'thingtwo))
              (gethash uuid my-hashtable)))

I assume this is no more or less efficient than let-ting the gethash,
manipulating the value, then using puthash to put it back in. Now I've
written this:

(macroexp-let2 nil entry (gethash uuid my-hashtable)
  (setf entry (append (list (list 'thingone 'thingtwo))
                      entry)))

This is a simplistic example, but -- is this actually going to be any
faster or more efficient than the first version? Does it only access the
hashtable once? Have I just been blinded by the shiny?

Any insights very welcome!

Thanks,
Eric




reply via email to

[Prev in Thread] Current Thread [Next in Thread]