mcons in dr racket

喜夏-厌秋 提交于 2019-11-30 12:44:47

Do you know what language are you using in your #lang line? The rest of the instructions below are assuming that you're using a #lang line.


If you are in #lang r5rs and you display or write the values, you should see the output you expect.

> (define p (list 1 2))
> (display p)
(1 2)
> (set-car! p 'one)
> (display p)
(one 2)

If you just type the values bare in Interactions, DrRacket will print them, and that uses the representation you're seeing. In DrRacket, you can customize the way that values print. Here's the process, step-by-step:

  1. Go to the Language menu, and select Choose Language. You should see the language dialog pop up.

  2. If the button on the lower left says Show Details, click it, and the dialog window should expand to include customizations.

  3. Look for the Output Style option. There should be four choices: Constructor, Quasiquote, write, and print. Select write style, and then press Ok to confirm the customization.

Once you do this, then:

> (display (list 1 2))
(1 2)
> (write (list 1 2))
(1 2)
> (list 1 2)
{1 2}

It will still print slightly differently than you expect, using curly braces, because it's trying to notate that the list structure is mutable.

If this bothers you, we can fix that. Add the following line near the top of your program (but after the #lang line).

(#%require r5rs/init)

This line pulls in a Racket-specific module called r5rs/init that tries to improve r5rs compliance; in particular, the braces should finally print as round ones for mutable pairs.

> (display (list 1 2))
(1 2)
> (write (list 1 2))
(1 2)
> (list 1 2)
(1 2)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!