[Top][All Lists]

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

Re:New lisp library -- cell.el

From: Zhu Zihao
Subject: Re:New lisp library -- cell.el
Date: Fri, 28 Feb 2020 16:51:58 +0800 (CST)

I can't send my file for unknown reason. So I post it to Github


At 2020-02-28 14:21:11, "Zhu Zihao" <address@hidden> wrote:

In last month I sent an email to request for some comments on weak reference facilities in Emacs. Now I create a new lisp library -- cell.el, which implemented weak reference in Elisp using weak hash table and some more util.

There are 3 kinds of cell in cell.el

- Option :: Giving "existence" information for a value, Like Maybe type in Haskell or Optional type in Java.
- Box :: Like a single element vector, create a mutable storage.
- Weak :: Weak reference I mentioned above.

IMO, these can help user to build Elisp application in more convenient way.

For a simple example.

(plist-get '(:key nil) :key) ; => nil
(plist-get '(:key nil) :val) ;=> nil

By using Option Cell, we can differentiate these two status.

(defun clear-plist-get (plist key)
  (pcase (plist-member plist key)
    (`(,_k ,v)
      (cell-option-some v))

(let ((plist '(:key nil)))
  (plist-get plist :key)                ;=> nil
  (plist-get plist :val)                ;=> nil

  (clear-plist-get plist :key)          ;=> Some(nil)
  (clear-plist-get plist :val)          ;=> None

I don't want to break the behaviour of plist-get, just a example to show the power of Option Cell. And there are detailed description in ;;; Commentary section.

Would you consider this to be included in Emacs core, or publish it on GNU ELPA?



reply via email to

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