Skip to content

Instantly share code, notes, and snippets.

@shirok
Created May 22, 2016 22:26
Show Gist options
  • Save shirok/60aae4d77cdd9ecd9528caef0d495ffb to your computer and use it in GitHub Desktop.
Save shirok/60aae4d77cdd9ecd9528caef0d495ffb 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 (map (^a (if (is-a? a <kwoted>)
(~ a'fn)
a))
(cons operand (delete operator args)))])
(unless operator
(error "No operator in application form:" (cons operand args)))
(apply operator operands)))
(define-class <kwoted> ()
((fn :init-keyword :fn)))
(define (& fn) (make <kwoted> :fn fn))
#|
gosh> ((& number?) ("abc" 123 "def" list) find)
123
gosh> (define (sagasu lis fn) ((& fn) find lis))
sagasu
gosh> (("abc" 123 "def" list) sagasu (& number?))
123
|#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment