A proof-of-concept demonstrating how to implement Object-Oriented Programming concepts in Common Lisp and make them available in Maxima as if they were native features.
This project shows how to:
- Implement a class-like structure in Common Lisp
- Create methods and encapsulation for the class
- Provide a clean Maxima interface that hides the Lisp implementation details
- Use the resulting "class" naturally in Maxima code
vector-class.lisp- Core Lisp implementation of a 2D vector classvector-interface.mac- Maxima wrapper functions providing clean syntaxdemo.mac- Complete demonstration of the vector class functionality
- Start Maxima in the project directory
- Load the demo:
load("demo.mac"); - Or load just the interface:
load("vector-interface.mac");
/* Create vectors */
v1: vector(3, 4);
v2: vector(1, 2);
/* Vector operations */
v3: vector_plus(v1, v2); /* Addition */
v4: vector_times(v1, 2); /* Scalar multiplication */
/* Properties */
mag: magnitude(v1); /* Magnitude: 5 */
dot: dot_product(v1, v2); /* Dot product: 11 */
/* Display */
display_vector(v1); /* [3, 4] */
- Encapsulation: Vector components are protected within the structure
- Methods: Operations like addition, scaling, magnitude calculation
- Type checking: Predicates to verify object types
- Error handling: Meaningful error messages for invalid operations
- Vector creation:
vector(x, y) - Component access:
vec_x(v),vec_y(v) - Vector arithmetic:
vector_plus(v1, v2),vector_times(v, scalar) - Vector properties:
magnitude(v),dot_product(v1, v2) - Utilities:
unit_vector(v),angle_between(v1, v2) - Type checking:
vectorp(v)
- Maxima 5.x
- Common Lisp implementation (SBCL, CCL, CLISP, etc.)
The implementation uses Common Lisp's defstruct to create a vector class with automatic constructor, accessor, and predicate functions. All Lisp functions intended for Maxima use start with $ to follow Maxima's naming convention for Lisp interop.
The Maxima interface layer provides more natural function names and additional utility functions, making the vector class feel like a native Maxima feature.