Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Donald E. Knuth's Homepage (stanford.edu)
29 points by dorkwood on June 1, 2024 | hide | past | favorite | 12 comments


Last month, Knuth was playing with an Othello program written in CWEB [1].

    for (k=0;k<8;k++)
      @<If direction |k| allows a move, |return 1|; otherwise |continue|@>;
    return 0;
This part looks confusing. There must be some actual code in the loop body, but it all looks like pseudo code?! How does CWEB process this?

[1] https://www-cs-faculty.stanford.edu/~knuth/programs/othello....


This is the original Knuth-style "literate programming", and being able to do this is approximately the entire point of CWEB.

BTW, note that the .w source file is not meant to be read directly: it is intended to be run through cweave (which generates a .tex file), and then typeset. In this case, I have a (not very up-to-date) repo at https://github.com/shreevatsa/knuth-literate-programs of the literate programs from Knuth's website, and othello.pdf is here: https://shreevatsa.github.io/knuth-literate-programs/program...

You're referring to section 4 of the program, which occurs at the bottom of page 2 here: https://shreevatsa.github.io/knuth-literate-programs/program... — in the typeset version, the text "If direction k allows a move, return 1; otherwise continue" is followed by the number 5, which means that the contents are in section 5 of the program. If you go to section 5 which is at the top of the next page (if viewing the PDF on a screen, you can simply click on the 5), you'll see the contents of the section (followed by "This code is used in section 4").

(It's also possible to define some code across multiple sections, e.g. the "<Subroutines 3>;" referenced in section 1 is defined across sections 3, 4, 6. All these conventions may seem unnecessary for a small program but they were devised for the medium-length (~20k lines) Pascal program TeX: https://mirrors.ctan.org/info/knuth-pdf/tex/tex.pdf and it's how Knuth now finds it most comfortable to program for programs of any length.)

(How does CWEB process this: ctangle replaces the text with the body of the loop; you could think of the entire `If direction |k| allows a move, |return 1|; otherwise |continue|` as a parameter-less macro with a long name, which is replaced by the preprocessor.)


It's right below that:

  @ @<If direction |k| allows a move, |return 1|; otherwise |continue|@>=
  {
    for (ii=i+deli[k],jj=j+delj[k],l=0;board[ii][jj]>=0;
    ...


https://ctan.org/pkg/cweb?lang=en - This has some reference documentation.

@< ... @> provides a section name. In text rendered form these become references, in code blocks when the code is generated it'll substitute in the referenced code.


Knuth got the memo—he wrote a well-known rejoinder to it; it's not surprising to find him using goto.


https://dl.acm.org/doi/10.1145/356635.356640

Structured Programming with go to Statements, Knuth, 1974


What's with those Chinese names (see both https://www-cs-faculty.stanford.edu/~knuth/faq.html#asian and https://www-cs-faculty.stanford.edu/~knuth/vita.pdf)? Why did they become part of his identity?


What do you mean? It says it right there on the FAQ:

> 高德纳 is my Chinese name, given to me in 1977 by Frances Yao.

A quick search indicates that Frances Yao is a colleague of Knuth's:

> Frances Foong Chu Yao (Chinese: 儲楓; pinyin: Chǔ Fēng) is a Taiwanese-American mathematician and theoretical computer scientist. [1]

As for why someone might assume a Chinese name, consider how many Chinese people in our industry assume Western names for the sake of working with us. Perhaps he's just returning the favor. It might also be compared to linguistic accomodation. [2]

[1]: https://en.wikipedia.org/wiki/Frances_Yao [2]: https://en.wikipedia.org/wiki/Communication_accommodation_th...


My guess it is partially addressed in the Non-Latin names section of the "Help Wanted" section. ...because I want to celebrate the fact that computer science is a fantastic worldwide enterprise.

https://www-cs-faculty.stanford.edu/~knuth/help.html


Knuth is so famous that Google translates his Chinese name as "Knuth" rather than a literal translation.


I like the fact that he doesn’t use email anymore. If I got to his level the first thing I’d do would be to hire an assistant to deal with all phone calls, emails and letters


My hero! I would never have stayed in “computer things” had I not read Donald’s volumes.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: