Created
May 22, 2016 22:26
-
-
Save shirok/60aae4d77cdd9ecd9528caef0d495ffb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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