Two examples:
#lang racket
(define (create-function-that-show-number n)
(display "*")
(lambda ()
(displayln n)))
;Create the function
(define f7 (create-function-that-show-number 7))
;Use it
(displayln "Hello")
(f7)
(displayln "World!")
;---
;Something more complex
The outer function must return the inner function (or otherwise make it
reachable, perhaps inside some data structure). For example:
> (define (make-counter init)
(define (counter)
(set! init (add1 init))
init)
(displayln "Making a counter!")
counter)
> (define count-from-f
Thank you so much. This is extremely helpful and instructive.
One thing I don't understand: how do you call or access an inner function
after its outer function has completed?
On Fri, Dec 16, 2016 at 5:41 AM, George Neuner wrote:
> On Thu, 15 Dec 2016 06:03:54 -0800 (PST), NeverTooOldToCode
>
3 matches
Mail list logo