67 lines
2.1 KiB
Markdown
67 lines
2.1 KiB
Markdown
# 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:
|
|
``` common-lisp
|
|
(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.
|
|
```common-lisp
|
|
#[foo (bar) (baz) (quux)]
|
|
;; C++: foo.bar().baz().quux()
|
|
```
|
|
|
|
To call a method, just write it after the object:
|
|
``` common-lisp
|
|
#[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):
|
|
```common-lisp
|
|
#[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:
|
|
``` common-lisp
|
|
#[object get-something]
|
|
;; => (get-something object)
|
|
```
|
|
|
|
To access slots directly, use the `:slot` keyword:
|
|
``` common-lisp
|
|
#[object :slot slot-name]
|
|
;; => (slot-value object 'slot-name)
|
|
```
|
|
|
|
You can also just use the `O!` macro directly:
|
|
|
|
``` common-lisp
|
|
(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.
|