3 ms·
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
by int_19h 2y ago
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).
- layer8 2y agoYou are right regarding nil, I was mixing this up with Turbo Pascal/Delphi strings.