首页 > 解决方案 > 如何在另一个函数中使用嵌套函数作为球拍语言的参数?

问题描述

我想在定义中创建函数:

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

然后将其用作另一个函数中的参数

(execute 400 400 example '(func)))

没有(评估)功能。

标签: functionfunctional-programmingnestedracketnested-function

解决方案


没有必要引用。

#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

推荐阅读