胡松涛
unread,May 26, 2011, 9:11:23 AM5/26/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to cn...@googlegroups.com
大家好,
我和yoyo在翻译gforth的文档,我把翻译好的部分放出来,希望大家能帮忙找出更多的错误。
-----------------译文---------------------
下一个:对齐教程,上一个:内存教程,上一级:教程
3.24 字符和字符串
在堆栈上,字符占用一个存贮单元,就和数字一样。在内存中他们有自己的大小(在大多数系统中是1个8位字节),因此,它需要用自己的词进行内存访问:
create v4
104 c, 97 c, 108 c, 108 c, 111 c,
v4 4 chars + c@ .
v4 5 chars dump
在堆栈上,字符串的首选表示是addr u-count
,其中addr是第一个字符的地址,同时 u-count是字符串中的字符数。
v4 5 type
你會得到如下的字符串常量
s" hello, world" .s
type
请确保在s" 和字符串之间有一个空格;s"
是一种常规的Forth词而且必须以空格分隔(你可以试试删除空格时会发生什么)。
然而,作为这个s" 的使用解释具有相当的局限性:该字符串只在下一次调用s"
之前存在(有些Forth系统保持多个这类字符串,但通常它们仍有一个有限的生命期)。
s" hello," s" world" .s
type
type
你还可以在一个定义中使用s"
,由此产生的字符串,会永远存在(当然,如果定义消失它也消失):
: foo s" hello," s" world" ;
foo .s
type
type
指定: Emit ( c -- ) 作为字符(而非数字)打印 c 。实做 type ( addr u -- ).
参考: 内存块。
--
Hu Songtao
works as an English Teacher in weekends
Skype: idisblueflash
Beijing, China