在 Forth 中打印双引号

har*_*per 7 forth

该单词."打印一个字符串。更准确地说,它将 和 字符串编译到当前编译的单词中的(.")下一个。"

但我怎样才能打印

这就是问题所在”。

与福斯?

ruv*_*vim 9

在 Forth-2012 系统(例如 Gforth)中,您可以使用字符串文字并通过单词进行转义,s\"如下所示:

: foo ( -- ) s\" That's the \"question\"." type ;
Run Code Online (Sandbox Code Playgroud)

在 Forth-94 系统(大多数标准系统)中,您可以使用任意解析和单词sliteral

: foo ( -- ) [ char | parse That's the "question".| ] sliteral type ;
Run Code Online (Sandbox Code Playgroud)

还可以提取字符串直到行尾(没有可打印分隔符);也可以提取多行字符串。

可以轻松定义特定情况的特定帮助程序。例如,请参阅s$由任意可打印字符分隔的字符串文字的单词,例如:

  s$ `"test" 'passed'` type
Run Code Online (Sandbox Code Playgroud)


agc*_*agc 7

老套:

34 emit
Run Code Online (Sandbox Code Playgroud)

输出:

"
Run Code Online (Sandbox Code Playgroud)

使用gforth

: d 34 emit ;
cr ." That's the " d ." question" d ." ." cr 
Run Code Online (Sandbox Code Playgroud)

输出:

That's the "question".
Run Code Online (Sandbox Code Playgroud)