From: Will Senn <will.senn@gmail.com>
To: TUHS main list <tuhs@minnie.tuhs.org>
Subject: Re: [TUHS] ratfor vibe
Date: Wed, 2 Feb 2022 22:00:21 -0600 [thread overview]
Message-ID: <d6064671-29c4-6c80-3735-1395c16dfc5c@gmail.com> (raw)
In-Reply-To: <c0fd1aec-55a8-54a4-94dc-748068d9e15d@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 4786 bytes --]
On 1/31/22 2:46 PM, Will Senn 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:
I thought I'd close the loop on the language side of this thread. I am
happy to report that ratfor (and fortran) is alive and well. It works on
my mac! The Software Tools book is awesome, if challenging. The first
chapter is particularly challenging as it takes a bit to figure out
where the authors are coming from and what they include, exclude, and
highlight... and why. The key to understanding the book, as a modern
reader, is to understand that the authors assume their readers are
fortran (or PL/I) programmers. Because of this, they don't explain
anything that would be obvious to said programmers (read, write, LUNs,
Hollerith cards, format, etc). In addition, they will push down details
of implementation until they practically disappear (think singularity...
annoyingly consistent in this regard). When they say something like "EOF
is a symbolic constant... We won't tell you what its value is, since the
particular value doesn't matter", they really mean it. Unfortunately, in
order to actually implement stuff, you gotta know what every symbolic
constant and macro replacement is :).
For example, even in the tiny copy program example, from the
introductory chapter, once you include the primitive getc and putc
subroutines, there are 7 symbolic constants: MAXLINE, MAXCARD, NEWLINE,
STDIN, STDOUT, EOF, SPACE and character, which is really an integer and
gets replaced with integer by some mythical preprocessor (chapter 8).
Anyhow, in the modern world, MAXLINE and MAXCARD don't really have
meaning, but they can magically be treated as lines of a file, the rest
do have meaning, but they don't evaluate to the same things in
Fortran-land as in modern-land. STDIN is 5 and STDOUT is 6 (card reader
and punch LUNs, again some magic that lets them be treated as terminal
input and output), EOF is -1, SPACE is 32, NEWLINE is 10. Anyhow, long
story just a bit shorter, replace those constants, swap character for
integer, and combine getc, putc, and copy and yahoo, a working copy
program that works in v7, 4.xBSD, and Mac OS X Mojave (and BSD, etc),
without any further modifications... at all.
Included for the curioius (copynew.r):
# on v7
# $ ratfor -C copynew.r > copynew.f
# $ f77 -o copynew copynew.f
# on mac
# $ ratfor77 -C copynew.r > copynew.f
# $ gfortran -o copynew copynew.f
# $ ./copynew
# This is a test.
# This is a test.
# CTRL-d
# $
# getc (simple version) - get characters from standard input
integer function getc(c)
integer buf(81), c
integer i, lastc
data lastc /81/,buf(81) /10/
lastc = lastc + 1
if(lastc > 81) {
read(5, 100, end=10) (buf(i), i = 1, 80)
100 format(80 a 1)
lastc = 1
}
c = buf(lastc)
getc = c
return
10 c = -1
getc = -1
return
end
# putc (simple version) - put characters on the standard output
subroutine putc(c)
integer buf(80), c
integer i, lastc
data lastc /0/
if (lastc > 80 | c == 10) {
for (i = lastc + 1; i <= 80; i = i + 1)
buf(i) = 32
write(6, 100) (buf(i), i = 1, 80)
100 format(80 a 1)
lastc = 0
}
if (c != 10) {
lastc = lastc + 1
buf(lastc) = c
}
return
end
# copy - copy input characters to output
integer getc
integer c
while(getc(c) != -1)
call putc(c)
stop
end
Of course, it's criminal to have all those hardcoded magic numbers,
wouldn't it be swell if there were some sort of macro facility?... oh,
wait, that's what Chapter 8's all about... I can't wait.
Will
[-- Attachment #2: Type: text/html, Size: 6184 bytes --]
next prev parent reply other threads:[~2022-02-03 4:01 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-31 20:46 Will Senn
2022-02-01 15:37 ` arnold
2022-02-01 15:52 ` Ralph Corderoy
2022-02-01 16:58 ` Clem Cole
2022-02-01 17:02 ` silas poulson
2022-02-02 7:47 ` arnold
2022-02-03 5:47 ` [TUHS] more about Brian Rich Morin
2022-02-03 7:44 ` markus schnalke
2022-02-03 8:18 ` Rich Morin
2022-02-04 2:23 ` Adam Thornton
2022-02-04 2:34 ` [TUHS] more about Brian... [really Rust] Jon Steinhart
2022-02-04 13:07 ` Thomas Paulsen
2022-02-04 23:18 ` Dan Cross
2022-02-04 3:28 ` [TUHS] more about Brian Dan Stromberg
2022-02-04 5:11 ` Rich Morin
2022-02-04 21:22 ` [TUHS] Go vs. Rust, and etc. (was: more about Brian...) Greg A. Woods
2022-02-04 21:37 ` Richard Salz
2022-02-04 22:32 ` Steffen Nurpmeso
2022-02-04 23:05 ` Thomas Paulsen
2022-02-04 23:15 ` Seth J. Morabito
2022-02-05 1:41 ` Adam Thornton
2022-02-04 7:38 ` [TUHS] more about Brian Andy Kosela
2022-02-04 8:10 ` Steve Nickolas
2022-02-04 8:44 ` markus schnalke
2022-02-04 9:16 ` Steve Nickolas
2022-02-04 18:54 ` John Cowan
2022-02-04 19:45 ` Thomas Paulsen
2022-02-04 20:28 ` Hellwig Geisse
2022-02-04 21:03 ` Jim Capp
2022-02-04 22:30 ` Steffen Nurpmeso
2022-02-04 22:25 ` Steffen Nurpmeso
2022-02-06 0:56 ` Larry McVoy
2022-02-06 1:10 ` Will Senn
2022-02-06 4:52 ` Rob Pike
2022-02-06 4:58 ` Dan Halbert
2022-02-06 5:06 ` Will Senn
2022-02-06 6:19 ` Ed Carp
2022-02-06 6:27 ` Rob Pike
2022-02-06 6:40 ` Stuart Remphrey
2022-02-06 6:44 ` Bakul Shah
2022-02-06 19:08 ` Steffen Nurpmeso
2022-02-06 12:52 ` Ralph Corderoy
2022-02-06 13:14 ` Ed Carp
2022-02-06 14:13 ` Dan Cross
2022-02-06 14:15 ` Larry McVoy
2022-02-06 16:31 ` Warner Losh
2022-02-06 18:36 ` [TUHS] more about Brian... [ really GC vs malloc/free languages ] Jon Steinhart
2022-02-06 19:27 ` Jon Steinhart
2022-02-06 19:33 ` Warner Losh
2022-02-06 19:37 ` Jon Steinhart
2022-02-06 20:21 ` [TUHS] COFF is over there Ralph Corderoy
2022-02-06 16:16 ` [TUHS] more about Brian Brad Spencer
2022-02-08 5:22 ` Ed Carp
2022-02-03 18:57 ` [TUHS] ratfor vibe silas poulson
2022-02-04 8:26 ` arnold
2022-02-04 19:41 ` John Cowan
2022-02-10 15:18 ` Ralph Corderoy
2022-02-03 4:00 ` Will Senn [this message]
2022-02-03 4:31 ` Al Kossow
2022-02-03 5:16 ` Warner Losh
2022-02-03 20:00 ` Adam Thornton
2022-02-04 6:06 ` Ori Idan
2022-02-04 17:35 ` Adam Thornton
2022-02-04 17:44 ` Will Senn
2022-02-01 18:19 Noel Chiappa
2022-02-01 18:47 ` Clem Cole
2022-02-01 19:10 ` Dan Cross
2022-02-01 19:39 ` Clem Cole
2022-02-01 21:21 ` Dan Cross
2022-02-01 21:33 ` Clem Cole
2022-02-01 23:12 ` John Cowan
2022-02-01 19:39 ` Richard Salz
2022-02-01 22:30 ` Erik E. Fair
2022-02-02 0:54 ` Yeechang Lee
2022-02-01 21:50 ` Win Treese
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d6064671-29c4-6c80-3735-1395c16dfc5c@gmail.com \
--to=will.senn@gmail.com \
--cc=tuhs@minnie.tuhs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).