简体   繁体   English

在球拍中定义引用过程?

[英]define quote process in racket?

I have this couple of lines that I'm running on drracket, I can't understand the output 我有这几行我在drracket上运行,我无法理解输出

> (define 'a 5)
> 'b
. . ..\..\Program Files\Racket\share\pkgs\drracket\drracket\private\rep.rkt:1088:24: b: undefined;
 cannot reference an identifier before its definition
> '0
5

is quote redefined? 是重新定义的报价? why 'b isn't working and '0 is 5? 为什么'b不工作而'0是5?

First, symbols are atomic values. 首先,符号是原子值。 They cannot be treated like variables. 它们不能像变量那样对待。

Anyway, your first line expands to: 无论如何,你的第一行扩展到:

(define (quote a) 5)

which is shorthand for defining functions in racket. 这是在球拍中定义功能的简写。 So yes, you are redefining quote . 所以是的,你正在重新定义quote

When you try to run 'b , you're running (quote b) , where it expects a variable b to have some value, which is does not. 当你试图运行'b ,你正在运行(quote b) ,它期望变量b有一些值,但事实并非如此。 That's why you receive the error, cannot reference an identifier before its definition . 这就是您收到错误的原因, cannot reference an identifier before its definition

When you try to run '0 , you're running (quote 0) . 当您尝试运行'0 ,您正在运行(quote 0) 0 is a valid value, and it becomes the value for a in your new function. 0是有效值,它将成为新函数中a的值。 So, the function evaluates as normal, and returns 5. 因此,函数评估为正常,并返回5。

In other words, it's not just 0 that is a valid argument. 换句话说,它不仅仅是0,它是一个有效的参数。

> (define 'a 5)
> (define b 12345)
> 'b
5
> '0
5
> '123454321
5

Check out the Racket documentation on symbols . 查看有关符号Racket文档 Symbols don't contain values; 符号不包含值; they are values. 他们价值观。 You'll want to use variables instead ( (define a 5) ). 您将要使用变量( (define a 5) )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM