Search code examples
functionfunctional-programmingnestedracketnested-function

How to use nested function in another function as argument in racket language?


I would like to create function inside definition:

(define example
'(
  (define (func)
   (rectfc 200 0 "blue")
   )
  )
 )

and then use it as arguments in another function

(execute 400 400 example '(func)))

without (eval) function.


Solution

  • There is no need for quoting.

    #lang racket
    
    (define (run-f args)
      (define (add-one n) ; <- defining a function locally
        (+ n 1))          ; 
      (map-f   add-one    ; <- passing into another function
               args))
    
    (define (map-f f args)
      (map f              ; <- using the function that
           args))         ;    was passed in
    
    
    (run-f '(1 2 3))
    ; = 2 3 4