.gitignore | ||
LICENSE | ||
objective-lisp.asd | ||
objective-lisp.lisp | ||
README.md |
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 reader
macro for the [
and ]
characters (although you can change these 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...)
Slot accessors, and other methods that don't take additional arguments, can be written without enclosing parentheses:
[object get-something]
;; => (get-something object)
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)
To access slots directly, use the :slot
keyword:
[object :slot slot-name]
;; => (slot-value object 'slot-name)
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.