https://github.com/samth/racket-send-exp
Terse syntax for object-oriented message sending
https://github.com/samth/racket-send-exp
Last synced: 3 months ago
JSON representation
Terse syntax for object-oriented message sending
- Host: GitHub
- URL: https://github.com/samth/racket-send-exp
- Owner: samth
- Created: 2014-11-03T14:21:11.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-11-03T14:21:34.000Z (over 11 years ago)
- Last Synced: 2026-03-01T22:52:35.802Z (4 months ago)
- Size: 102 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Convenient OO message sending for Racket
## Invoking methods
In Racket, invoking a message `foo` on an object `bar` is done with
```racket
#lang racket
...
(send bar foo arg1 arg2 ...)
```
To make this a little more convenient, prefix your language
specification with `send-exp`, and use curly-braces instead:
```racket
#lang send-exp racket
...
{foo bar arg1 arg2 ...}
```
Note that the selector comes *first*, with the receiver argument
coming *second*.
## Defining methods
In addition, using `#lang send-exp ...` adds new syntax for defining
methods in a class. In addition to the normal ways of defining a
method, you can also use `(define {method self arg ...} ...)` and
`(define/override {method self arg ...} ...)`:
```racket
#lang send-exp racket
...
(class object%
...
(define {foo self arg1 arg2 ...}
...))
```
The syntax
```racket
(define {selector receiver arg ...) body ...)
```
is equivalent to
```racket
(define/public (selector arg ...)
(let ((receiver this))
body ...))
```
and `define/override` with curly-braces is analogously equivalent to a
use of the underlying `define/override` syntax.
## Abstracting over method calls
In addition to the above, you can use `{method}` anywhere you would
use `(lambda (receiver) {method receiver})`. This only works for unary
methods at present.