Skip to content

Instantly share code, notes, and snippets.

Created May 12, 2011 19:53
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
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)))
(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)
Copy link

This is very cool. Customizing ftw.

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