方案:如何产生 '(5 . (5)) [英] Scheme: how to produce '(5 . (5))

查看:14
本文介绍了方案:如何产生 '(5 . (5))的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了各种 cons 和 append 组合来生成 '(5 . (5)) 但我不能.有什么办法吗?

I have tried all kinds of combinations of cons and append to produce '(5 . (5)) but I couldn't. Is there any way?

推荐答案

冒着听起来像比尔克林顿的风险,这取决于你所说的生产"是什么意思.

At the risk of sounding like Bill Clinton, it depends on what you mean by "produce".

如果你的意思是产生一个在屏幕上打印为 '(5 . (5)) 的值,那么你有点不走运,因为这个值打印为 '(5 5).

If you mean "produce a value that prints on the screen as '(5 . (5)), then you're sort of out of luck, because this value prints as '(5 5).

对于类似的示例:我如何生成数字 1e-1 ?好吧,试着输入它;这和 0.1 一样,如果你输入 1e-1,它会打印为 0.1.

For a similar example: how do I produce the number 1e-1 ? Well, try typing it in; this is the same as 0.1, and if you type in 1e-1, it's going to print as 0.1.

但是,您可以评估

#lang racket
(= 0.1 1e-1)

...你会看到它们是相同的数字.

... and you'll see that they're the same number.

以同样的方式,尝试评估

In the same way, try evaluating

#lang racket
(equal? '(5 . (5)) (list 5 5))

你会看到这是两种写入相同值的方式.

and you'll see that these are two ways of writing the same value.

这篇关于方案:如何产生 '(5 . (5))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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