Nu Class Reference

NuCell

The building blocks of lists.

Superclass: NSObject
Declared in: tools/nuke, objc/Nu.h

NuCells are used to build lists and accept several powerful messages for list manipulation. In Lisp, these are called "cons" cells after the function used to create them.

Each NuCell contains pointers to two objects, which for historical reasons are called its "car" and "cdr". These pointers can point to objects of any Objective-C class, which includes other NuCells. Typically, the car of a NuCell points to a member of a list and its cdr points to another NuCell that is the head of the remainder of the list. The cdr of the last element in a list is nil. In Nu, nil is represented with the [NSNull null] object.

Methods

+ (id) cellWithCar: (id) car
cdr: (id) cdr
Create a new cell with a specifed car and cdr.

in objc/Nu.h

- (NSMutableArray *) array
Get an array containing the elements of a list.

in objc/Nu.h

- (NSUInteger) count
Get the number of elements in a list. Synonymous with length.

in objc/Nu.h

- (NSUInteger) length
Get the length of a list beginning at a NuCell.

in objc/Nu.h

- (id) reduce: (id) block
from: (id) initial
Iterate over each element of the list headed by a NuCell, using the provided block to combine elements into a single return value.

in objc/Nu.h

- (id) map: (id) block
Iterate over each element of the list headed by a NuCell, applying the provided block to each element, and returning a list of the results.

in objc/Nu.h

- (id) find: (id) block
Iterate over each element of the list headed by a NuCell, returning the first element for which the provided block evaluates non-nil.

in objc/Nu.h

- (id) select: (id) block
Iterate over each element of the list headed by a NuCell, returning a list containing the elements for which the provided block evaluates non-nil.

in objc/Nu.h

- (id) eachWithIndex: (id) block
Iterate over each element of the list headed by a NuCell, calling the specified block with the element and its index as arguments.

in objc/Nu.h

- (id) eachPair: (id) block
Iterate over each pair of elements of the list headed by a NuCell, calling the specified block with the two elements as arguments.

in objc/Nu.h

- (id) each: (id) block
Iterate over each element of the list headed by a NuCell, calling the specified block with the element as an argument.

in objc/Nu.h

- (id) comments
Get any comments that were associated with a NuCell in its Nu source file.

in objc/Nu.h

- (bool) atom
Returns false. NuCells are not atoms. Also, nil is not an atom. But everything else is.

in objc/Nu.h

- (id) evalWithContext: (NSMutableDictionary *) context
Treat the NuCell as the head of a list of Nu expressions and evaluate those expressions.

in objc/Nu.h

- (NSMutableString *) stringValue
Get a string representation of a list. In many cases, this can be parsed to produce the original list.

in objc/Nu.h

- (id) lastObject
Get the last object in a list by traversing the list. Use this carefully.

in objc/Nu.h

- (void) setCdr: (id) c
Set the cdr of a NuCell.

in objc/Nu.h

- (void) setCar: (id) c
Set the car of a NuCell.

in objc/Nu.h

- (id) cdr
Get the cdr of a NuCell.

in objc/Nu.h

- (id) car
Get the car of a NuCell.

in objc/Nu.h

- (id) join
Join the elements of a list into a string with list elements separated by spaces.

in tools/nuke