News for hackers. Stuff that matters.
Re:COMEFROM by ryandvm on Thursday November 17, 2011 @10:47AM (#3247986)
Some elements of Aspect Oriented Programming are comparable to the COMEFROM statement.

http://en.wikipedia.org/wiki/Aspect-oriented_programming#See...

Re:COMEFROM by brlewis on Thursday November 17, 2011 @11:22AM (#3248128)
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)