Re:COMEFROM
by skynirka on Thursday November 17, 2011 @10:22AM
(#3247899)
Have any examples of languages that implement this?
[ Parent
| on HN ]
Some elements of Aspect Oriented Programming are comparable to the COMEFROM statement.
http://en.wikipedia.org/wiki/Aspect-oriented_programming#See...
Here's an AOP-style comefrom syntax you can play with by setting DrRacket's language to R5RS:
(define-syntax comefrom
(syntax-rules ()
((comefrom function expr ...)
(let ((old-function function))
(set! function
(lambda args
(begin expr ...)
(apply old-function args)))))))
(define (square x)
(* x x))
(define (hypotenuse a b)
(sqrt (+ (square a) (square b))))
(comefrom square
(display "I'm a square!\n"))
(hypotenuse 3 4)
The example in the Wikipedia article is more like this: (define-syntax comefrom
(syntax-rules ()
((comefrom function)
(call-with-current-continuation
(lambda (here)
(set! function here))))))
(define (noop)
; Do nothing
#t)
(define (main)
(let ((i 0))
(comefrom noop)
(if (< i 5)
(begin
(set! i (+ i 1))
(display "Hello world!\n")
(noop)))))
(main)
Re:COMEFROM
by InclinedPlane on Thursday November 17, 2011 @12:03PM
(#3248295)
To some extent any inversion of control style framework works like this. It can be more or less befuddling depending on the straightforwardness of the framework. Declarative style programming such as sql, xslt, or msbuild also tend to work this way, which can be maddening to debug.
There's a CPAN module for it in Perl 5 (with support for fork() on parallel comefroms):
http://search.cpan.org/dist/Acme-ComeFrom/lib/Acme/ComeFrom....