all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Zhu Zihao" <all_but_last@163.com>
To: emacs-devel@gnu.org
Subject: Re:New lisp library -- cell.el
Date: Fri, 28 Feb 2020 16:51:58 +0800 (CST)	[thread overview]
Message-ID: <5ba4e906.6dfb.1708afecaf2.Coremail.all_but_last@163.com> (raw)
In-Reply-To: <b3cbce2.31e2.1708a74bc6f.Coremail.all_but_last@163.com>

[-- Attachment #1: Type: text/plain, Size: 1544 bytes --]

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


https://github.com/cireu/emacs-cell














At 2020-02-28 14:21:11, "Zhu Zihao" <all_but_last@163.com> 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))
    (_
     (cell-option-none))))

(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?





 

[-- Attachment #2: Type: text/html, Size: 2803 bytes --]

  reply	other threads:[~2020-02-28  8:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-28  6:21 New lisp library -- cell.el Zhu Zihao
2020-02-28  8:51 ` Zhu Zihao [this message]
2020-02-28 15:43 ` Stefan Monnier
2020-02-28 16:51   ` Zhu Zihao
2020-02-29  3:30     ` Stefan Monnier
2020-02-29  6:48       ` Zhu Zihao
2020-02-29 14:09         ` Stefan Monnier
2020-03-01  7:43           ` Zhu Zihao
2020-03-05 15:52             ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5ba4e906.6dfb.1708afecaf2.Coremail.all_but_last@163.com \
    --to=all_but_last@163.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.