[TUHS] ratfor vibe

arnold at skeeve.com arnold at skeeve.com
Wed Feb 2 01:37:34 AEST 2022


Will,

This will be a high level reply. I undoubtedly have some details wrong, as
I wasn't inside Bell Labs.

	Sherman, set the wayback machine for 1974.
		-- Mr. Peabody

In 1974, Unix was still young, and while C existed, it was not widespread.
The predominant programmng language in use at the time in Bell Labs
and in many, many other places, was Fortran.  For our purposes, Fortran IV
and Fortran 66 are the same thing: the only control flow constructs the
language had was 'if', 'goto' and a 'do' loop that could only count up.
The only data structure was the array.

Structured Programming had started to take hold in the Computer Science
community, with lots of discussion and papers about what the best control
flow structures were, and so on.

At the time there were preprocessors for Fortran that made it easier to
program in.  I don't know what got him started, by Brian Kernighan decided
to write one that would give Fortran control flow constructs similar or
identical to those of C.  This was ratfor, for RATional FORtran. He used
C and Yacc (which was also fairly young) to do this.

Recognizing that the Unix environment was very pleasant, but that the
wide world wouldn't drop everything they had to move to it, he and
P.J. (Bill) Plauger used ratfor to create a bunch of tools that provided
functionality similar or identical to many of the Unix utilities,
and wrote a book on the tools, using it as a platform to at the
same time teach good programming practices.  This is

https://www.amazon.com/Software-Tools-Brian-W-Kernighan/dp/020103669X/ref=sr_1_5?crid=LXBHQKV9D0QP&keywords=software+tools&qid=1643720166&s=books&sprefix=software+tools%2Cstripbooks%2C220&sr=1-5

which I STRONGLY recommend getting and reading, even almost 50 years
after it was published (1975 or 1976).

This book changed my life. Literally.

The original tools are in the TUHS archives. (If anyone has not synched
their copy, please do so, there were some errors in the files that I
have recently fixed and which Warren has put in place.)

(A modernized version of UNIX ratfor is at
https://github.com/arnoldrobbins/ratfor, so you don't have to use V7 to
get it. The doc is included and it's easy to make PDF of it.)

The book and tools were extremely popular into the early 80s, until Unix
itself started to spread.  Debbie Scherer can give the history of her
group, which took the tools and made them portable to all kinds of
computing environments. At Georgia Tech, 3 students took the tools and
adapted them into a lovely environment for use on Pr1me systems, which
were otherwise rather less user-friendly.

At Bell Labs, Brenda Baker wrote 'struct' which read Fortran and turned
it into ratfor; see the recent list archives for more on my efforts to bring
that program into the 21st century. (Apologies for the self plugs. :-)

In ~ 1981, Kernighan and Plauger rewrote the tools in Pascal and redid
the book to go with it. This is

https://www.amazon.com/Software-Tools-Pascal-Brian-Kernighan/dp/0201103427/ref=sr_1_3?keywords=software+tools+in+pascal&link_code=qs&qid=1643727958&sourceid=Mozilla-search&sr=8-3

which I also recommend getting a copy of. This in turn led to Kernighan's
famous "Pascal is not my favorite programming language" memo (which is also
in my github :-).

The Pascal tools are also in the TUHS archive.

I hope this helps.

Arnold


Will Senn <will.senn at gmail.com> wrote:

> All,
>
> I have been doing some language exploration in v7/4.3bsd and came across 
> Software Tools (not the pascal version). It's written using ratfor, 
> which I had seen in the v7 UPM. I fired up v7 and tried my hand at the 
> first example:
>
>     # copy - copy input characters to output
>              integer getc
>              integer c
>
>              while(getc(c) != EOF)
>                      call putc(c)
>              stop
>              end
>
> The first thing I noticed was that it read more like C than Fortran (I 
> know C quite well, Fortran just a smidge)... awesome, right? So I ran 
> the preprocessor on it and got the following f77 code:
>
>     c copy - copy input characters to output
>            integer getc
>            integer c
>     c     while
>     23000 if(.not.(getc(c) .ne. eof))goto 23001
>               call putc(c)
>               goto 23000
>     c     endwhile
>     23001 continue
>            stop
>            end
>
> Cool. The way it translated the EOF test is weird, but ok. Trying to 
> compile it results in complaints about missing getc and putc:
>
>     $ f77 copy.f
>     copy.f:
>         MAIN:
>     Undefined:
>     _getc_
>     _putc_
>     _end
>
> Ah well, no worries. I know that they're in the c lib, but don't about 
> fortran libs... Meanwhile, over on 4.3BSD, it compiles without issue. 
> But running it is no joy:
>
>     $ ./a.out
>     This is a test
>     $
>
> I remembered that the authors mentioned something about EOF, so I 
> tweaked the code (changed EOF to -1) and rebuilt/reran:
>
>     $ ./a.out
>     This is a test
>     This is a test
>     $
>
> Fascinating. Dunno why no complaints from F77 about the undefined EOF 
> (or maybe mis-defined), but hey, it works and it's fun.
>
> I'm curious how much ratfor was used in bell labs and other locations 
> running v6, v7, and the BSD's. When I first came across it, I was under 
> the impression that it was a wrapper to make f66 bearable, but the 
> manpage says it's best used with f77, so that's not quite right. As 
> someone coming from c, I totally appreciate what it does to make the 
> control structures I know and love available, but that wasn't the case 
> back then, was it? C was pretty new... Was it just a temporary fix to a 
> problem that just went away, or is there tons of ratfor out there in the 
> wild that I just haven't seen? I found ratfor77 and it runs just fine on 
> my mac with a few tweaks, so it's not dead:
>
>     ratfor77 -C copy.r | tee copy.f
>     C Output from Public domain Ratfor, version 1.0
>     C copy - copy input characters to output
>            integer getc
>            integer c
>     23000 if(getc(c) .ne. eof)then
>            call putc(c)
>            goto 23000
>            endif
>     23001 continue
>            stop
>            end
>
> What's the story? Oh, and in v6 it looks like it was rc - ratfor 
> compiler, which is not present in v7 or 4.3BSD - is there a backstory 
> there, too?
>
> Will
>
>
>


More information about the TUHS mailing list