Naming for Line and Space Adders and Removers

(DELIMIT, SPACED, UNSPACED) [are] very nice! Might I suggest that you could add to this set of functions unlines, an immensely useful function from Haskell:

ghci> unlines ["a list","of lines","of text"]
"a list\nof lines\nof text\n"

(Haskell also has the reverse function lines, which splits up a string into a list of lines. There’s also unwords/words, which do the same thing for all whitespace.)

1 Like

Er, to be clear, I should note that the naming wasn’t my main focus here. I was simply suggesting that it’s convenient to have a function for adding newlines, not just spaces.

Well, it's what the discussion becomes once I agree that having them would be nice. :slight_smile:

Hm, sounds backwards for something that makes lines out of structure...!

There are some old functions called ENLINE and DELINE which I had been eyeing to retake for this particular purpose...

>> deline "a list\nof lines\nof text\n"
== ["a list" "of lines" "of text"]

>> enline ["a list" "of lines" "of text"]
== "a list\nof lines\nof text\n"

...which would let you keep LINES for a noun variable name.

The reverse of SPACED could be DESPACED.

Er, so I guess by that thinking we could use LINED and DELINED ...?

Stickler that I am for enforcing newlines at end of file, I'd probably want the default for DELINED to ensure a terminal line unless you used a refinement. DELINED/RELAX ?

1 Like

Yep, the naming is slightly weird, but it’s one of those things which makes sense in the context of Haskell’s history. For Rebol, I agree that ENLINE/DELINE sound better.

Insofar as I understand the history: in Haskell it’s a counterpart to lines, which splits up a string into lines:

ghci> text = "some\nlines\nof\ntext"
ghci> lines text
["some","lines","of","text"]

So, when they wanted the reverse, it made sense to call it unlines! Same story with words (splitting a string into its words) vs unwords (concatenating a list of words to a single string). And everyone just got used to that situation.

I'll mention that Rebol does have SPLIT. Operates on strings, arrays...

>> split "your words here" space
== ["your" "words" "here"]

>> split [your elements + (are) here + + so split them] '+
== [[your elements] [(are) here] [] [so split them]]

It's dialected weirdly, so the thing you're splitting by can be a block but then it doesn't mean that block literally:

>> split "1234567812345678" [4 4 2 2 1 1 1 1]
== ["1234" "5678" "12" "34" "5" "6" "7" "8"]

I've never paid much attention to it, so I haven't put in my 2 cents on the design.

I don't want to change SPACED to ENSPACED :-/ so following the pattern and doing LINED and DELINED is probably the most consistent if it's SPACED and DESPACED.

A little strange, but seems okay:

>> spaced ["your" "words" "here"]
== "your words here"

>> despaced "your words here"
== ["your" "words" "here"]

>> lined ["a list" "of lines" "of text"]
== "a list\nof lines\nof text\n"

>> delined "a list\nof lines\nof text\n"
== ["a list" "of lines" "of text"]

LINED would be evaluative, like SPACED, unless you use an @[...] block.

Some people might be confused by DESPACED vs. UNSPACED. :-/ An interesting past naming decision was that DEQUOTE once meant "remove all quoting levels" while UNQUOTE meant "remove one quoting level"... but DEQUOTE and UNQUOTE seemed so interchangeable that DEQUOTE was named NOQUOTE

A post was split to a new topic: Haskell's Composable Splitting Combinators