←back to thread

71 points susam | 3 comments | | HN request time: 0s | source
1. layer8 ◴[] No.43675809[source]
> There is no null string, perhaps because Pascal uses the doubled quote notation to indicate a quote embedded in a string:

    'This is a '' character'
That doesn’t seem like a good explanation. There’s nothing preventing a tokenizer from interpreting two quotes not followed by a third quote as an empty string literal. In fact, that’s what current Pascal compilers accept (e.g. `writeln('')`).

However, an empty string and nil are also the same in Pascal, there is no distinction between an empty string and the absence of a string. This is because in early computing, strings weren’t separate objects that you pointed to (and hence could be a null pointer), but more like (usually fixed-size) arrays allocated as part of a larger contiguous memory structure. The array could be empty (based on some length variable), but it couldn’t not be there as part of the fixed memory layout.

Actually, in certain systems strings couldn’t even be empty, in the sense that there was no stored size in addition to the fixed-length array. Instead you padded the rest of the array with spaces. The CHAR type in SQL (as opposed to VARCHAR) is a remnant of that practice.

replies(1): >>43676618 #
2. int_19h ◴[] No.43676618[source]
Empty string and nil are not at all the same in Pascal. Pascal, even in its most basic version, still had pointers, and nil was the null pointer. You could have pointers to strings (and other kinds of arrays), as well.

What made standard Pascal problematic wrt string handling is that it did not have array NEW nor pointer arithmetic. So if you wanted to heap-allocate ARRAY[1..100] OF CHAR, that was fine; but there was no way to get a pointer to N bytes on the heap where N is determined at runtime; and even if you could do that, somehow, you still wouldn't be able to use that pointer as an array by indexing through it.

Interestingly enough standard Pascal did support allocating variable-length data structures, but only in form of variant records (roughly analogous to discriminated unions in ML or enums in Rust, but with multi-level nesting and the ability to define a common sequence of fields shared by all variants at any level).

replies(1): >>43676746 #
3. layer8 ◴[] No.43676746[source]
You are right regarding nil, I was mixing this up with Turbo Pascal/Delphi strings.