objective-lisp/README.md
2022-02-22 04:56:07 +00:00

2.1 KiB

objective-lisp

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

Usage

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++: foo.bar().baz().quux()

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

License

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.