emacs-devel
[Top][All Lists]
Advanced

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

Re: possible json.el optimization: json-alist-p and json-plist-p recursi


From: Ted Zlatanov
Subject: Re: possible json.el optimization: json-alist-p and json-plist-p recursion
Date: Fri, 14 Oct 2011 10:09:40 -0400
User-agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.90 (gnu/linux)

On Thu, 13 Oct 2011 12:07:22 -0400 Ted Zlatanov <address@hidden> wrote: 

TZ> Good points, I had the `car-safe' and `cdr-safe' calls left over from
TZ> earlier code, and I was copying into p unnecessarily.  This is better, I
TZ> think:

#+begin_src lisp
(defun gnus-sync-json-alist-p (list)
  "Non-null if and only if LIST is an alist."
  (while (consp list)
    (setq list (if (consp (car list))
                   (cdr list)
                 'not-alist)))
  (null list))

(defun gnus-sync-json-plist-p (list)
  "Non-null if and only if LIST is a plist."
  (while (consp list)
    (setq list (if (and (keywordp (car list))
                        (consp (cdr list)))
                   (cddr list)
                 'not-plist)))
  (null list))
#+end_src

Emacs Lisp doesn't have `alist-p' or `plist-p' which these functions
could provide.  So instead of fixing just json.el, can I move these
functions to the core and rewrite json.el accordingly?  I think that
would be useful.  

But here's why I didn't just do it: these functions are exclusive,
meaning they don't accept a general list that has cons cells.  So this
example list is OK with `assq' but would fail the proposed `alist-p':

(assq 1 '((1 . 2) 3))

WDYT?  Should I change the name to `[ap]list-pure-p' or something like
that?  Or is this too limited to be generally useful?

Thanks
Ted




reply via email to

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