2019-10-09 13:13:56 +02:00
|
|
|
;;; dotted.el --- Working with dotted pairs in Elisp -*- lexical-binding: t -*-
|
2020-09-01 11:17:43 +02:00
|
|
|
|
2019-10-09 13:13:56 +02:00
|
|
|
;; Author: William Carroll <wpcarro@gmail.com>
|
2020-09-01 11:17:43 +02:00
|
|
|
;; Version: 0.0.1
|
|
|
|
;; URL: https://git.wpcarro.dev/wpcarro/briefcase
|
|
|
|
;; Package-Requires: ((emacs "24.3"))
|
2019-10-09 13:13:56 +02:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;; Part of my primitives library extensions in Elisp. Contrast my primitives
|
|
|
|
;; with the wrapper extensions that I provide, which expose immutable variants
|
|
|
|
;; of data structures like an list, alist, tuple, as well as quasi-typeclasses
|
|
|
|
;; like sequence, etc.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Dependencies
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2019-10-09 13:13:56 +02:00
|
|
|
(require 'prelude)
|
|
|
|
(require 'macros)
|
2020-09-02 16:23:46 +02:00
|
|
|
(require 'cl-lib)
|
2019-10-09 13:13:56 +02:00
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Library
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(cl-defun dotted-new (&optional a b)
|
2020-09-02 16:23:46 +02:00
|
|
|
"Create a new dotted pair of A and B."
|
2019-10-09 13:13:56 +02:00
|
|
|
(cons a b))
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun dotted-instance? (x)
|
2019-10-09 13:13:56 +02:00
|
|
|
"Return t if X is a dotted pair."
|
|
|
|
(let ((b (cdr x)))
|
|
|
|
(and b (atom b))))
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun dotted-first (x)
|
2019-10-09 13:13:56 +02:00
|
|
|
"Return the first element of X."
|
|
|
|
(car x))
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun dotted-second (x)
|
2019-10-09 13:13:56 +02:00
|
|
|
"Return the second element of X."
|
|
|
|
(cdr x))
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Tests
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(progn
|
2020-08-31 18:05:31 +02:00
|
|
|
(prelude-assert
|
2020-09-01 11:17:43 +02:00
|
|
|
(equal '(fname . "Bob") (dotted-new 'fname "Bob")))
|
2020-08-31 18:05:31 +02:00
|
|
|
(prelude-assert
|
2020-09-01 11:17:43 +02:00
|
|
|
(dotted-instance? '(one . two)))
|
2020-08-31 18:05:31 +02:00
|
|
|
(prelude-refute
|
2020-09-01 11:17:43 +02:00
|
|
|
(dotted-instance? '(1 2 3))))
|
2019-10-09 13:13:56 +02:00
|
|
|
|
|
|
|
(provide 'dotted)
|
|
|
|
;;; dotted.el ends here
|