April 2017
Intermediate to advanced
316 pages
9h 33m
English
We need to have a way to append items to LinkedList; we name it cons.
cons refers to a fundamental function in most dialects of the Lisp programming language that constructs memory objects that hold two values or pointers to values.
It is loosely related to the object-oriented notion of a constructor/initializer, and more closely related to the constructor function of an algebraic data type system.
In FP jargon, operators that have a similar purpose, especially in the context of list or collection processing, are pronounced cons.
We implement cons as follows:
func cons(_ element: Element) -> LinkedList { return .node(data: element, next: self) }
This simple method appends the data to the front of LinkedList; in other words, it is ...
Read now
Unlock full access