Instantly share code, notes, and snippets.

Embed
What would you like to do?
Objective-R: Objective-C-like syntax for method calls in Racket
#lang racket ; Requires Racket >= 5.1.1
(provide (rename-out (objective-r-read read)
(objective-r-read-syntax read-syntax)))
(require syntax/stx)
(define (rewrite-method-calls stx)
(if (stx-list? stx)
(let ((stx* (stx-map rewrite-method-calls stx)))
(if (eq? (syntax-property stx 'paren-shape) #\[)
(match (stx->list stx*)
((list obj msg args ...)
#`(send #,obj '#,msg #,@args)))
stx*))
stx))
(define (objective-r-read . args)
(let ((stx (apply objective-r-read-syntax #f args)))
(if (eof-object? stx) stx (syntax->datum stx))))
(define (objective-r-read-syntax . args)
; TODO: Do something with the rest of the arguments
(rewrite-method-calls (read-syntax (first args) (second args))))
; Example:
(objective-r-read (open-input-string "[[document get-element-by-id stuff] remove]"))
; => (send (send document 'get-element-by-id stuff) 'remove)
@olleolleolle

This comment has been minimized.

Show comment
Hide comment
@olleolleolle

olleolleolle May 25, 2011

This is very cool. Customizing ftw.

olleolleolle commented May 25, 2011

This is very cool. Customizing ftw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment