Why does newLISP limit string literals to 2048 characters?

261 Views Asked by At

I'm trying to write usage instructions for this newLISP program I've made but it keeps complaining about the string being too long.

ERR: string token too long : "$$$$$$$$&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"

I spent some ten minutes cursing newLISP and coming up with paranoid theories like, maybe you shouldn't have quotes in the string or maybe it'll work when I use raw strings({}), until I started chopping the string. It reached a point where the message dissappeared leaving the help message very unhelpful. Turns out newLISP doesn't like strings that have more than 2048(2^11) characters. Soo,

Why put a limit on the number of characters in a string literal?
Why 2048 characters?

Increasing cell memory to 128MB(saw it the manual) doesn't change anything. The only solution that works now(a hackish one), is splitting the help string into two strings each under 2048 characters then concatenating them with string.
The other strange thing is that any string that has 2048+ characters is printed differently in the repl:

> (dup "&" 2048)
    [text]&&&&&&&&&&&&&& .....
           ......
                &&&&&&&&&&&&&&&[/text]


> (dup "&" 2040)
    "&&&&&&&&&&&&&&&&&&& .....
        .....
                &&&&&&&&&&&&&&&"
1

There are 1 best solutions below

2
On

There are three ways to do strings:

  • in quotes - escape characters are processed - limited to 2048 chars
  • in braces - no escape characters are processed - limited to 2048 chars
  • in tags - no escapes are processed - unlimited length

From the manual:

Quoted strings cannot exceed 2,048 characters. Longer strings should use the [text] and [/text] tag delimiters. newLISP automatically uses these tags for string output longer than 2,048 characters.

Strings can be quite long:

> (quiet (set 's (dup "&" 10E8))) ; don't bother to show the string :)
> (length s)
1000000000
> (10000 20 s)
"&&&&&&&&&&&&&&&&&&&&"
>

The only problem you'll have is when you want to process source code in strings that might contain a [/text] tag before you want the string to really end. It doesn't look like you're at that point yet... :)