Nu Class Reference

NuBlock

The Nu representation of functions.

Superclass: NSObject
Declared in: objc/block.h

A Nu Block is an anonymous function with a saved execution context. This is commonly referred to as a closure.

In Nu programs, blocks may be directly created using the do operator. Since blocks are objects, they may be passed as method and function arguments and may be assigned to names. When a block is assigned to a name, the block will be called when a list is evaluated that contains that name at its head; the remainder of the list will be evaluated and passed to the block as the block's arguments.

Blocks are implicitly created by several other operators.

The Nu function operator uses blocks to create new named functions.

The Nu macro operator uses blocks to create macros. Since macros evaluate in their callers' contexts, no context information is kept for blocks used to create macros.

The imethod and cmethod operators use blocks to create new method implementations. When a block is called as a method implementation, its context includes the symbols self and super. This allows method implementations to send messages to the owning object and its superclass.

Methods

- (NuCell *) body
Get the body of code that is evaluated during block evaluation.

in objc/block.h

- (NSMutableDictionary *) context
Get the lexical context of the block. This is a dictionary containing the symbols and associated values at the point where the block was created.

in objc/block.h

- (id) evalWithArguments: (id) cdr
context: (NSMutableDictionary *) calling_context
Evaluate a block using the specified arguments and calling context.

in objc/block.h

- (id) evalWithArguments: (id) cdr
context: (NSMutableDictionary *) calling_context
self: (id) object
Evaluate a block using the specified arguments, calling context, and owner. This is the mechanism used to evaluate blocks as methods.

in objc/block.h

- (id) initWithParameters: (NuCell *) a
body: (NuCell *) b
context: (NSMutableDictionary *) c
Create a block. Requires a list of parameters, the code to be executed, and an execution context.

in objc/block.h

- (NuCell *) parameters
Get the list of parameters required by the block.

in objc/block.h

- (NSString *) stringValue
Get a string representation of the block.

in objc/block.h