我怎样才能在 Rebol 中打开单词的换行状态?
How can I turn on a word's new-line state in Rebol?
我知道,我知道。 "What new-line state?",你问。
好吧,让我告诉你:
append [] w: first new-line [hello] on
== [
hello
]
W 现在是一个词,在附加到块时会创建一个新行。
你可以关闭它,例如在 Rebol 3 中这样:
append [] to word! w
== [hello]
但是一直没有找到好的开启方式。 Rebol 大师,你可以吗?
澄清:我正在寻找这样的东西:
append [] f to word! "hello"
其中有一个换行符。
换行状态似乎是根据分配的 value 在赋值时是否有一个前面的换行符来分配给单词的(我会反省该陈述的正确性有一段时间了)。
此函数将相同的值(应保留上下文)重新分配给具有新换行状态的单词:
set-new-line: func [
'word [word!]
state [logic!]
][
set/any word first new-line reduce [get/any word] state
]
我们还可以测试给定单词的换行状态:
has-new-line?: func [
'word [word!]
][
new-line? reduce [get/any word]
]
正在使用:
>> x: "Foo"
== "Foo"
>> has-new-line? x
== false
>> reduce [x]
== ["Foo"]
>> set-new-line x on
== "Foo"
>> has-new-line? x
== true
>> reduce [x]
== [
"Foo"
]
>> reduce [set-new-line x on set-new-line x off set-new-line x on]
== [
"Foo" "Foo"
"Foo"
]
回答原始问题(我知道,因为我在另一个化身中问过它):
f: func [w][first new-line append copy [] :w on]
我知道,我知道。 "What new-line state?",你问。 好吧,让我告诉你:
append [] w: first new-line [hello] on
== [
hello
]
W 现在是一个词,在附加到块时会创建一个新行。
你可以关闭它,例如在 Rebol 3 中这样:
append [] to word! w
== [hello]
但是一直没有找到好的开启方式。 Rebol 大师,你可以吗?
澄清:我正在寻找这样的东西:
append [] f to word! "hello"
其中有一个换行符。
换行状态似乎是根据分配的 value 在赋值时是否有一个前面的换行符来分配给单词的(我会反省该陈述的正确性有一段时间了)。
此函数将相同的值(应保留上下文)重新分配给具有新换行状态的单词:
set-new-line: func [
'word [word!]
state [logic!]
][
set/any word first new-line reduce [get/any word] state
]
我们还可以测试给定单词的换行状态:
has-new-line?: func [
'word [word!]
][
new-line? reduce [get/any word]
]
正在使用:
>> x: "Foo"
== "Foo"
>> has-new-line? x
== false
>> reduce [x]
== ["Foo"]
>> set-new-line x on
== "Foo"
>> has-new-line? x
== true
>> reduce [x]
== [
"Foo"
]
>> reduce [set-new-line x on set-new-line x off set-new-line x on]
== [
"Foo" "Foo"
"Foo"
]
回答原始问题(我知道,因为我在另一个化身中问过它):
f: func [w][first new-line append copy [] :w on]