Skip to content

Instantly share code, notes, and snippets.

@sritchie
Last active December 30, 2020 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sritchie/8dea6507051bc485246a98a1877c1e70 to your computer and use it in GitHub Desktop.
Save sritchie/8dea6507051bc485246a98a1877c1e70 to your computer and use it in GitHub Desktop.
;; Here is the smoking gun...
(define (f x)
(lambda (cont)
(cont (lambda (y) (* x y))
(lambda (g) (g x)))))
;; (D f) is:
(lambda (cont)
(cont (lambda (y) (+ x y))
(lambda (g) (g x))))
;; If I pass the first function into the second in the continuation, the whole
;; thing acts like (+ x x). So this should equal 10:
(((d f) 5) (lambda (f1 f2) (f2 f1)))
;; but in fact errors, due to equation (24d) in the paper. In fact, it passes if
;; you take Sussman's suggestion and implement tag replacement for functions as
;; identity!
;;
;; (But then of course your careful Church-boxed example fails.)
;;
;; Further notes from my investigation:
;;
;; This fails now because `f1` and `f2` both RETURN
;; differentials that have closed over the required `new`
;; tag from the outermost scope.
;;
;; On the way out, when the outer scope tries to swap `new`
;; back in for `old`, we get an error. The line that does
;; this is:
;;
;; (replace-differential-tag oldtag newtag)
;;
;; in `scmutils`, inside of `replace-dx-function`.
@sritchie
Copy link
Author

Output from latest scmutils:

(define (f x)
  (lambda (cont)
    (cont (lambda (y) (* x y))
          (lambda (g) (g x)))))
#| f |#

1 ]=> (((D f) 5) (lambda (f1 f2) (f2 f1)))

;INSERT-DIFFERENTIAL-TAGS: 3 (3)
;To continue, call RESTART with an option number:
; (RESTART 1) => Return to read-eval-print level 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment