Skip to content

Instantly share code, notes, and snippets.

@shirok
Created May 22, 2016 22:12
Show Gist options
  • Save shirok/e10f63a500e9e08abccd103024d3578a to your computer and use it in GitHub Desktop.
Save shirok/e10f63a500e9e08abccd103024d3578a to your computer and use it in GitHub Desktop.
(define-method object-apply ((operand <top>) arg . args)
(let* ([args (cons arg args)]
[operator (find (^a (or (is-a? a <procedure>)
(is-a? a <generic>)))
args)]
[operands (cons operand (delete operator args))])
(unless operator
(error "No operator in application form:" (cons operand args)))
(apply operator operands)))
#|
gosh> (+ 1 1)
2
gosh> (1 + 1)
2
gosh> (1 1 +)
2
gosh> ("abc" (1 2 3 +) list ("ghi" string-append "jkl"))
("abc" 6 "ghijkl")
|#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment