Module index

Module: ObjNL

Objective newLISP - Real Object Oriented Programming for newLISP

Version: 1.0
Author: Greg Slepak
Location: http://www.taoeffect.com/newlisp/ObjNL.lsp.txt

Introductory Guide

The official guide is highly recommended reading if you are planning on using Objective newLISP.

What is Objective newLISP?

Objective newLISP is a new and exciting way of doing real object oriented programming in newLISP where instances are passed by reference and can easily hold references to other objects while maintaining their own mutable state.

It supports most of the object oriented concepts you'll find in other languages. It supports inheritance, interfaces (aka protocols), as well as class and instance variables.

Objects are passed by reference, so there's no problem with passing an object through multiple user-defined functions and modifying it.

Accessing instance variables no longer requires a function call plus a list traversal. Simply access the symbol directly.

Objective newLISP also enhances newLISP by providing convenient and safe macros for deep reference access.

With Objective newLISP it is possible to take full advantage of everything object-oriented programming has to offer.


There are very few conventions in ObjNL, but there are some:


newLISP 10.1.9 or higher is strongly recommended, but any version after 10.1 should work.

Version history

1.0 • initial release

- § -


syntax: ObjNL

ObjNL is the root class for Objective newLISP. All other classes ultimately inherit from it. It defines several instance and class variables:

- § -


syntax: (ObjNL:ObjNL)

The constructor is the default function. It is called by instantiate.

The default implementation simply returns true.

- § -


syntax: (ObjNL:dealloc)

Called by deallocate to give the object an opportunity to release resources and objects.

- § -


syntax: (ObjNL:equals ctx-obj)

Provides a method for classes to define what it means for objects to be equal.

The default implementation returns true if two objects are the same instance.

- § -


syntax: (new-class sym-class [ctx-super [list-interfaces]])
parameter: sym-class - The name of the class
parameter: ctx-super - The superclass, accessible through @super
parameter: list-interfaces - Any contexts to "mixin", accessible through @interfaces

return: The context of the new class created.

- § -


syntax: (instantiate ctx-class [arg-1 ...])

Returns a new instance of ctx-class by calling its constructor and passing in any arguments. If the constructor returns nil then the instance is deallocated and nil is returned.

The returned object must be deallocated using the deallocate function.

- § -


syntax: (add-interface ctx-iface ctx-obj)

Uses the function new to add ctx-iface to the object and adds the interface to ctx-objs @interfaces.

- § -


syntax: (deallocate ctx-obj)

Calls the objects dealloc method and then delete's the object.

NOTE: On versions of newLISP prior to 10.1.9 this is a fairly slow operation, make sure to use at least version 10.1.9 with Objective newLISP.

- § -


syntax: (implements? ctx-interface ctx-obj)

return: true or nil as to whether this ctx-obj implements ctx-interface.

- § -


syntax: (retain ctx-obj)

Increment's ctx-obj's retain count and returns the object.

- § -


syntax: (release ctx-obj)

Decrement's ctx-obj's retain count. Deallocates the object if the retain count hits zero.

- § -


syntax: (autorelease ctx-obj)

Adds ctx-obj to the current MAIN:@autorelease pool and returns the object.

- § -


syntax: (push-autorelease-pool)

Pushes a new autorelease pool onto the MAIN:@autorelease stack.

- § -


syntax: (pop-autorelease-pool)

Pops the current MAIN:@autorelease pool and releases the objects in it.

- § -


syntax: (. obj field-1 [field-2 [field-n]])

The dot macro is used for "deep value access":

 (new-class 'Foo)
 (new-class 'Bar)
 (context Bar)
 (define (Bar:Bar f)
 	(setf foo f)
 	true ; -> do not deallocate us if 'f' is nil
 (context Foo)
 (define (Foo:Foo b)
 	(setf bar b)
 	true ; -> do not deallocate us if 'b' is nil
 (context MAIN)
 (setf f (instantiate Foo (instantiate Bar)))
 (set (.& f bar foo) f) ; => Foo#1
 (. f bar foo bar)      ; => Bar#1

- § -


syntax: (.& obj field-1 [field-2 [field-n]])

The dot-reference macro is similar to the dot macro, except it returns the context-qualified symbol for the final field instead of its value ("deep symbol access"). This allows you to combine it with set.

see: '.' macro for example usage.

- ∂ -

generated with newLISP  and newLISPdoc