/persistent-list

A persistent/immutable list implementation.

Primary LanguageCommon LispEclipse Public License 2.0EPL-2.0

persistent-list

A fast Persistent/Immutable List implementation.

Usage

Given that persistent-list collides with several important function definitions in the :common-lisp namespace it is recommended that thsi library is used with a local nickname. For example, like this:

(defpackage my-package
    (:use #:cl)
    (:local-nicknames (#pl:persistent-list)))

Constructor: list

(pl:list 0 1 2 3)
;; (0 1 2 3)

(pl:list)
;; nil

Prepend: cons

(pl:cons 1 nil)
;; (1)
(pl:cons 1 (pl:list 2 3))
;; (1 2 3)

First: first

(pl:first (pl:list 1 2 3))
;; 1
(pl:first nil)
;; nil

Rest:

(pl:rest (pl:list 1 2 3))
;; (2 3)
(pl:rest nil)
;; nil
(pl:pop (pl:list 1 2 3))
;; (2 3)
(pl:pop nil)
;; error

Nth:

(pl:nth (pl:list "a" "b" "c") 1)
;; "b"
(pl:nth nil 1)
;; nil

Length

(pl:length (pl:list 1 2 3))
;; 3
(pl:length nil)
;; nil

Equality

(pl:list-equal (pl:list 1 2 3) (pl:list 1 2 3))
;; t
(pl:list-equal nil nil)
;; nil

Map

(pl:map '1+ (pl:list 1 2 3))
;; (2 3 4)

Reduce

(pl:reduce '+ (pl:list 1 2 3))
;; 6
(pl:reduce '+ (pl:list 1 2 3) 10)
;; 16

Dolist

(pl:dolist (x (pl:list 1 2 3))
   (print x))
;; "1"
;; "2"
;; "3"

Type checking

(pl:persistent-lisp-p (pl:list 1 2 3))
;; t
(pl:persistent-lisp-p nil)
;; t