简体   繁体   English

球拍中的报价行为

[英]behavior of quote in racket

I'm used to (quote x) evaluating to x , (quote (xyz)) evaluating to (xyz) , and (car (quote (xyz)) evaluating to x . The reasoning is simple: quote is a special form that does not evaluate its argument, but simply returns it as is.我习惯于(quote x)评估x(quote (xyz))评估(xyz)(car (quote (xyz))评估x 。推理很简单:quote 是一种特殊形式不评估它的参数,而只是按原样返回它。

I just started using Racket, and it thinks that (quote x) evaluates to (quote x) , (quote (xyz)) evaluates to (quote (xyz)) , and (car (quote (xyz)) evaluates to (quote x) .我刚开始使用 Racket,它认为(quote x)评估为(quote x)(quote (xyz))评估为(quote (xyz)) ,并且(car (quote (xyz))评估为(quote x)

Well, actually, it prints these as 'x , '(xyz) , and 'x , respectively, but that's the same thing.好吧,实际上,它分别将这些打印为'x'(xyz)'x ,但这是同一回事。

Can someone explain the reasoning here?有人可以解释这里的推理吗? If, for some reason, (quote (xyz)) evaluates to (quote (xyz)) , shouldn't the car of that then be quote ?如果出于某种原因, (quote (xyz))计算结果为(quote (xyz)) ,那么该汽车不应该是quote吗? Where does (quote x) come from? (quote x)从哪里来?

As far as I can tell, Racket, throughout the entire computation, internally behaves just as I'm used to, except that when it comes time to print the final result, it wraps it in a quote form.据我所知,在整个计算过程中,Racket 的内部行为与我习惯的一样,只是在打印最终结果时,它将其包装在报价表中。 Is this correct in all cases?这在所有情况下都是正确的吗? And if so, why would it want to do that?如果是这样,它为什么要这样做?

Racket evaluates the expressions in the same way as any Scheme. Racket 以与任何 Scheme 相同的方式评估表达式。 Racket however has in a special writer in the teaching languages.然而,Racket 在教学语言方面有一位特别的作家。 In DrRacket you can change the way values are printed.在 DrRacket 中,您可以更改打印值的方式。 In the language menu, click the advanced button, and then take a look at the printing options.在语言菜单中,单击高级按钮,然后查看打印选项。

Racket (language) prints out the result of top level forms, not only when entered in the interaction window (REPL), but always. Racket(语言)打印出顶级表单的结果,不仅在交互窗口(REPL)中输入时,而且总是。 It's to ease developing I guess and in real world applications you don't have statements that doesn't amount to anything so a real application wouldn't have these lines displayed since you have define and an expression to start your program and you could return (void) from it to force no output..我猜这是为了简化开发,在现实世界的应用程序中,您没有没有任何意义的语句,因此真实的应用程序不会显示这些行,因为您已经define和表达式来启动您的程序并且您可以返回(void) 从它强制不输出..

If you were to change language to either #!r6rs or #!r5rs you quickly see that the only way to get the result of an evaluation in the definitions window would be if you explicitly used display on the result.如果您将语言更改为#!r6rs#!r5rs您很快就会发现,在定义窗口中获得评估结果的唯一方法是在结果上明确使用display

No matter the language used, display displays it correctly.无论使用何种语言, display都能正确显示。 For a REPL-print the language and setting control how it displays.对于 REPL 打印,语言和设置控制它的显示方式。 Standard #!racket is to display in such way that putting it in a new expression wrapped with display would print exactly the same as if you would have wrapped the original expression with display.标准的#!racket 是以这样的方式显示的:将它放入一个用display包裹的新表达式中,打印出来的效果与您用 display 包裹原始表达式时的打印结果完全相同。

(define test 'hello-world)
(display test) ;; displays hello-world and not 'hello-world
test           ;; displays 'hello-world in #!racket, nothing in R6RS unless in interactions window

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

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