In section 51 of tex.web there is this:

name_of_file ← pool_name; { we needn’t set name length }

where name_of_file is (sectoin 26):

name_of_file : packed array [1 .. file name size ] of char;

and pool_name is (section 11):

pool_name = 'TeXformats:TEX.POOL                   ';
  { string of length file_name_size; tells where the string pool appears }

Is such string assignment a feature of Pascal? In which circumstances does Pascal allow to do string assignments? (like in section 51 above) Is the necessary condition that array and assigned string must have equal size?

Similar case arises in sections 520 and 521.

  • 1
    This isn't about TeX but about Pascal, so it belongs to StackOverflow IMO. Also a "feature of Pascal" is not really well-defined, especially since this code is older than any Pascal standard. But according to Standard Pascal, assignment of compatible string types is allowed (string types are compatible iff they have the same length) – Marcel Krüger Feb 21 '20 at 18:12
  • 1
    Personally I think the question is fine here, or at least not appropriate for StackOverflow or any other generic site: Knuth was programming against a specific version of Pascal (Pascal-H), which people not closely connected with TeX may not have dug into the special characteristics of. (BTW, the standard of Pascal that existed at that time is Pascal User Manual and Report by Kathleen Jensen and Niklaus Wirth published in 1975; see §10.) – ShreevatsaR Feb 21 '20 at 21:57
  • 3
    Anyway, I saw the previous question before seeing this, and I think my answer there happens to answer this as well (yes you can assign strings, i.e. arrays of chars, of the same length). – ShreevatsaR Feb 21 '20 at 21:58
  • @MarcelKrüger, in the original (Wirth) Pascal this is exactly how it was designed: you could asign arrays of characters as long as they had the same range of indices. – vonbrand Feb 21 '20 at 23:58

Yes, the Pascal reference that Knuth used allows only assignments of strings that have the same length. Strings in Pascal are arrays of base type char with an index type that is a subrange of integers, i.e., 1..n. And, of course, Knuth leaves no bytes unassigned. (That's why the pool_name gets file_name_size characters in your other question.)

In section 10 of tex.web Knuth states that he follows Jensen/Wirth's User Manual & Report of 1974; the original definition of the Pascal Language. He made some exceptions---clearly indicated in situations where the definition of the above mentioned book was obscure or clutter up the code. For example, in the case statement he accepted an else/otherwise part.

In the corrected printing of 1978 the book states on page 41 that a string with n>1 characters is a packed array [1..n] of char. The next sentence is ``Assignment (:=) is possible between operands of identical array types.''

I don't know much about the Pascal-H compiler that Knuth used. Later Pascals, for example, the standard for Extended Pascal, allows more flexible assignments for strings.

  • An else or otherwise extension of case was extremely common. – vonbrand Feb 22 '20 at 0:00
  • @vonbrand The extended case statement was available in many but not all Pascal implementations. That's why section 10 ends with "if no default mechanism is available, the case statements of TeX will have to be laboriously extended by listing all remaining cases. People who are stuck with such Pascals have, in fact, done this, successfully but not happily!". Also it was often available with a different syntax in each. (That's how I understand it, as I wrote here.) – ShreevatsaR Feb 22 '20 at 0:52
  • @ShreevatsaR I just read your answer for the previous question. You're right, it answers this question too. – Udo Wermuth Feb 22 '20 at 9:43
  • @vonbrand You are right such an extension was common. But as ShreevatsaR states in the above comment there was no universal solution at the time when Knuth did the programming how the case statement should be extended. The User Manual and Report defines case without a default case. – Udo Wermuth Feb 22 '20 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.