MarkI
MarkI

Reputation: 347

How can I turn on a word's new-line state in Rebol?

I know, I know. "What new-line state?", you ask. Well, let me show you:

append [] w: first new-line [hello] on
== [
    hello
]

W is a now a word that creates a new-line when appended to a block.

You can turn it off, for example this way in Rebol 3:

append [] to word! w
== [hello]

But I have not found a good way to turn it on. Can you, Rebol guru?

Clarification: I am looking for some 'f such that:

append [] f to word! "hello"

has a new-line in it.

Upvotes: 3

Views: 161

Answers (2)

MarkI
MarkI

Reputation: 132

To answer the original question (which I know, because I asked it, in another incarnation):

f: func [w][first new-line append copy [] :w on]

Upvotes: 2

rgchris
rgchris

Reputation: 3708

Seemingly the new-line state is assigned to the word based on whether the assigned value has a preceding new-line at the time of assignment (I'll ruminate on the correctness of that statement for a while).

This function reassigns the same value (should retain context) to the word with a new new-line state:

set-new-line: func [
    'word [word!]
    state [logic!]
][
    set/any word first new-line reduce [get/any word] state
]

We can also test the new-line state of a given word:

has-new-line?: func [
    'word [word!]
][
    new-line? reduce [get/any word]
]

In use:

>> 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"
]
  • should work in and

  • appears to work in v0.6.1 with one caveat: new-line? seems always to return true

Upvotes: 2

Related Questions