免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4031 | 回复: 4
打印 上一主题 下一主题

请教这是为什么?DrScheme中的string-set! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-07-11 21:44 |只看该作者 |倒序浏览
(define x "hello")
x
==>"hello"
(string-set! x 0 #\p)
==>string-set!: expects type <mutable string> as 1st argument, given: "hello"; other arguments were: 0 #\p ;;;;;;;;;;;;结果错误???

(define x (string #\h#\e#\l#\l#\o))
x
==>"hello"
(string-set! x 0 #\p)
x
==>"pello"  ;;;;;;;;结果正确

论坛徽章:
0
2 [报告]
发表于 2009-07-11 22:09 |只看该作者
3.3 strings

......

A string can be mutable or immutable. When an immutable string is provided to a procedure like string-set!, the exn:fail:contract exception is raised. String constants generated by the default reader (see Reading Strings) are immutable.

12.6.6 Reading Strings

When the reader encounters ", it begins parsing characters to form a string. The string continues until it is terminated by another "

论坛徽章:
0
3 [报告]
发表于 2009-07-11 23:10 |只看该作者
多谢。
查了一下r5rs,好像没有上面的表述。是什么书里的?

论坛徽章:
0
4 [报告]
发表于 2009-07-12 00:06 |只看该作者
DrScheme 自带的 help 文档。网上也有:

http://docs.plt-scheme.org/reference/strings.html

只读是 drscheme 的个性吧,我用 guile 试,"hello" 也是可改写的。

论坛徽章:
0
5 [报告]
发表于 2009-07-13 10:15 |只看该作者
原帖由 pass12163com 于 2009-7-11 23:10 发表
多谢。
查了一下r5rs,好像没有上面的表述。是什么书里的?


可变串应该不是标准scheme类型。
<scheme程序设计语言>也没有提到。
sicp里除了error用到串, 很少提及串这东西。 和Unix里到处都是字符串的情况真是巨大的差别。
把以前的东西暂时都忘了,才能学到scheme里遍地的“新”东西。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP