Skip to content

Foadsf/maxima-oop-lisp-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maxima OOP with Lisp - Vector Class Demo

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.

Overview

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

Files

  • vector-class.lisp - Core Lisp implementation of a 2D vector class
  • vector-interface.mac - Maxima wrapper functions providing clean syntax
  • demo.mac - Complete demonstration of the vector class functionality

Usage

  1. Start Maxima in the project directory
  2. Load the demo: load("demo.mac");
  3. Or load just the interface: load("vector-interface.mac");

Example

/* 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] */

Features Demonstrated

OOP Concepts

  • 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

Available 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)

Requirements

  • Maxima 5.x
  • Common Lisp implementation (SBCL, CCL, CLISP, etc.)

Technical Details

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.

About

Proof-of-concept demonstrating OOP implementation in Lisp for Maxima

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published