Syntactic sugar for object-oriented Lisp.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
~keith 7d85c12f3a
Fix bug with :slot access
9 months ago
.gitignore Initial commit 1 year ago
LICENSE Initial commit 1 year ago Rewrite as standard macro 9 months ago
objective-lisp.asd Rewrite as standard macro 9 months ago
objective-lisp.lisp Fix bug with :slot access 9 months ago


Syntactic sugar for object-oriented Lisp.

objective-lisp provides a simple, concise, and (slightly) more conventional syntax for accessing the slots and methods of objects. It defines a macro named O!, and a reader macro for #[...] (although you can change these characters in the code).


TL;DR: #[object (method args)] is like object.method(args) in C++.

First, to enable objective-lisp's syntax, just load the system:

(asdf:load-system 'objective-lisp)

objective-lisp's syntax takes the form of a special S-expression, contained in square brackets rather than parentheses. Each expression within acts upon the result of the previous one, like a chain of . (dot) operators in C-like languages.

#[foo (bar) (baz) (quux)]
;; C++:

To call a method, just write it after the object:

#[object (method args...)]
;; => (method object args...)

Under the hood, this just passes object as the first argument to method, so you can do stuff like this (I won't kinkshame you, but your coworkers might):

#[object (slot-value 'slot-name) (setf value)]
;; => #[(slot-value object 'slot-name) (setf value)]
;;  => (setf (slot-value object 'slot-name) value)

Slot accessors, and other methods that don't take additional arguments, can be written without enclosing parentheses:

#[object get-something]
;; => (get-something object)

To access slots directly, use the :slot keyword:

#[object :slot slot-name]
;; => (slot-value object 'slot-name)

You can also just use the O! macro directly:

(O! object :slot foo (do-something args...))
;; => (do-something (slot-value object 'foo) args...)


objective-lisp is public domain (CC0). You can do whatever you want with it. I don't really care about credit, it's just a silly little thing I wrote in a few hours. (And then rewrote just now because the syntax sucked.)

But if you find it useful, please let me know. I'd love to hear about it.