当地的球拍 [英] local in racket

查看:33
本文介绍了当地的球拍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读书中有关本地定义的内容,并且遇到了这个示例-

I am reading about local definitions in the book, and I came across this example-

(local ((define (f x) (+ x 5))
    (define (g alon)
      (cond
        [(empty? alon) empty]
        [else (cons (f (first alon)) (g (rest alon)))])))
  (g (list 1 2 3)))

local 在这里到底做了什么?

what exactly does local do here?

推荐答案

local 记录在 这里 作为其中之一的一部分HtDP 语言或在 此处 作为 的一部分本地 模块.让我们依次看看每一个.第一个是 HtDP:

local is documented either in here as part of one of the HtDP languages or in here as part of the local module. Let's see each one in turn. First the one in HtDP:

(local [definition ...] expression) 对表达式中使用的相关定义进行分组.每个定义可以是定义或定义结构.在评估 local 时,按顺序评估每个定义,最后评估正文表达式.只有局部内的表达式(包括定义和表达式的右侧)可以引用由定义定义的名称.如果本地定义的名称与顶级绑定相同,则内部名称会遮蔽"外部名称.也就是说,在本地内部,对该名称的任何引用都指向内部名称.

(local [definition ...] expression) Groups related definitions for use in expression. Each definition can be either a define or a define-struct. When evaluating local, each definition is evaluated in order, and finally the body expression is evaluated. Only the expressions within the local (including the right-hand-sides of the definitions and the expression) may refer to the names defined by the definitions. If a name defined in the local is the same as a top-level binding, the inner one "shadows" the outer one. That is, inside the local, any references to that name refer to the inner one.

接下来是 local 模块中的:

And next, the one in the local module:

(local [definition ...] body ...+) 与 letrec-syntaxes+values 类似,不同之处在于绑定的表达方式与在顶层或在 a模块体:使用define、define-values、define-syntax、struct等.定义通过部分扩展定义形式与非定义区分开来(见部分扩展).就像在顶层或模块体中一样,一个开始包装的序列被拼接到定义序列中.

(local [definition ...] body ...+) Like letrec-syntaxes+values, except that the bindings are expressed in the same way as in the top-level or in a module body: using define, define-values, define-syntax, struct, etc. Definitions are distinguished from non-definitions by partially expanding definition forms (see Partial Expansion). As in the top-level or in a module body, a begin-wrapped sequence is spliced into the sequence of definitions.

因此,根据使用的语言/模块,您将知道您找到的是哪个 local.很明显,这不是标准的特殊形式.

So depending on the language/modules in use, you'll know which local was the one you found. And clearly, it's not a standard special form.

这篇关于当地的球拍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆