[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: |
Sat, 29 Feb 2020 00:51:49 +0800 |
User-agent: |
Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (Gojō) APEL/10.8 EasyPG/1.0.0 Emacs/27.0 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) |
> Why not use nil for "none"? That would simplify your code and most
> likely would make for much more natural/idiomatic code in the clients of
> your library.
> [ Traditionally in Lisp when you need something like a "option` (aka
> `Maybe`) type, you use `(cons X nil)` for `some X` and `nil` for `none`. ]
I tend to keep None variant a singleton of cell-option. nil is over-overloaded
in Lisp programming. For example, if we want to store a nullable value in the
slot of cl-struct and we use nil as none. It's hard to differentiate "Slot is
unintialized" and "Slot is initialized with None".
> Why bother with those indirections?
Docstring generated by `cl-defstruct` may not suitable for us. An alias to make
a meaningful doc.
Or should we use (put 'cell-box-inner 'function-documentation ".....")?
> That makes every call to `cell-weak-get` allocate a new symbol only to
> throw it away. I'd recommend you define a top-level constant
Or use '(nil)? map.el use this. But IMO your solution (return nil for GCed weak
ref) is better.