Skip to content

Instantly share code, notes, and snippets.

@cr1901
Created June 28, 2015 08:19
Show Gist options
  • Save cr1901/c6d11e084dd8338d80a2 to your computer and use it in GitHub Desktop.
Save cr1901/c6d11e084dd8338d80a2 to your computer and use it in GitHub Desktop.
#lang racket
(define (my_closure x) ;Return a fcn which adds x to its input.
(define copy-of-x x)
(lambda (y)
(set! copy-of-x (+ copy-of-x y))
copy-of-x
)
)
(define copy-of-my-closure (my_closure 4))
((my_closure 4) 5) ;9
((my_closure 4) 5) ;9
(copy-of-my-closure 5) ;9
(copy-of-my-closure 5) ;14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment