The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] origin of string.h and ctype.h
       [not found] <mailman.919.1502645045.3779.tuhs@minnie.tuhs.org>
@ 2017-08-13 21:55 ` Johnny Billquist
  2017-08-13 22:26   ` Charles Anthony
  2017-08-14  0:02 ` Paul McJones
  1 sibling, 1 reply; 18+ messages in thread
From: Johnny Billquist @ 2017-08-13 21:55 UTC (permalink / raw)


On 2017-08-13 19:24, Dave Horsfall <dave at horsfall.org> wrote:
> On Sat, 12 Aug 2017, Steve Johnson wrote:
>> A little Googling shows that the IF I mentioned was called the
>> "arithmetic IF".
> Ah yes.  It was in FORTRAN II, as I recall.

Still there in FORTRAN 77.

>>  There was also a Computed GOTO that branched to one of N labels
>> depending on the value of the expression.
> I think that was still in FORTRAN IV?

Still there in FORTRAN 77.

>>  And an Assigned GOTO whose main use, as I remember, was to allow for
>> error recovery when a subroutine failed...
> A real ugly statement; you assigned a statement number to a variable, then
> did a sort of indirect GOTO (or did the compiler recognise "GOTO I")?

The compiler recognize "GOTO I". And I have to be assigned to a 
statement number (label). It has to be an integer variable, and when you 
assign it to a label, you cannot do any arithmetic with it anymore. And 
you assign it with a special statement. Thus, it can be used to store 
what label to jump to, but you cannot use arithmetic to set what it 
should jump to.

> How those poor devils ever debugged their code with such monstrous
> constructions I'll never know.

It's actually not that hard. All this stuff is fairly simple to deal 
with. The real horror in FORTRAN is EQUIVALENCE, which can give C a fair 
fight for real horror stories.

But of course, bad programmers can mess things up beyond belief in any 
language.

(And I never went beyond FORTRAN 77, so I don't know how current 
versions look like. I stayed with PDP-11s (well, still do), and nothing 
newer than FORTRAN 77 exists there. :-) )

	Johnny

-- 
Johnny Billquist                  || "I'm on a bus
                                   ||  on a psychedelic trip
email: bqt at softjar.se             ||  Reading murder books
pdp is alive!                     ||  tryin' to stay hip" - B. Idol


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [TUHS] origin of string.h and ctype.h
  2017-08-13 21:55 ` [TUHS] origin of string.h and ctype.h Johnny Billquist
@ 2017-08-13 22:26   ` Charles Anthony
  0 siblings, 0 replies; 18+ messages in thread
From: Charles Anthony @ 2017-08-13 22:26 UTC (permalink / raw)


On Sun, Aug 13, 2017 at 2:55 PM, Johnny Billquist <bqt at update.uu.se> wrote:

> On 2017-08-13 19:24, Dave Horsfall <dave at horsfall.org> wrote:
>
>> On Sat, 12 Aug 2017, Steve Johnson wrote:
>>
>>> A little Googling shows that the IF I mentioned was called the
>>> "arithmetic IF".
>>>
>> Ah yes.  It was in FORTRAN II, as I recall.
>>
>
> Still there in FORTRAN 77.
>
>  There was also a Computed GOTO that branched to one of N labels
>>> depending on the value of the expression.
>>>
>> I think that was still in FORTRAN IV?
>>
>
> Still there in FORTRAN 77.
>
>  And an Assigned GOTO whose main use, as I remember, was to allow for
>>> error recovery when a subroutine failed...
>>>
>> A real ugly statement; you assigned a statement number to a variable, then
>> did a sort of indirect GOTO (or did the compiler recognise "GOTO I")?
>>
>
> The compiler recognize "GOTO I". And I have to be assigned to a statement
> number (label). It has to be an integer variable, and when you assign it to
> a label, you cannot do any arithmetic with it anymore. And you assign it
> with a special statement. Thus, it can be used to store what label to jump
> to, but you cannot use arithmetic to set what it should jump to.
>
> How those poor devils ever debugged their code with such monstrous
>> constructions I'll never know.
>>
>
> It's actually not that hard. All this stuff is fairly simple to deal with.
> The real horror in FORTRAN is EQUIVALENCE, which can give C a fair fight
> for real horror stories.
>

IIRC, PRIMOS was written in FORTRAN, and they had an extension where you
could pass assigned GOTO variables as parameters and to jump globally; I
don't recall the stack semantics, but I would guess setjmp/longjmp style.

-- Charles
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20170813/fbac560f/attachment.html>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [TUHS] origin of string.h and ctype.h
       [not found] <mailman.919.1502645045.3779.tuhs@minnie.tuhs.org>
  2017-08-13 21:55 ` [TUHS] origin of string.h and ctype.h Johnny Billquist
@ 2017-08-14  0:02 ` Paul McJones
  2017-08-14 16:09   ` Paul Winalski
  1 sibling, 1 reply; 18+ messages in thread
From: Paul McJones @ 2017-08-14  0:02 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1173 bytes --]

On Sun, 13 Aug 2017, Dave Horsfall wrote:

> On Sat, 12 Aug 2017, Steve Johnson wrote:
> 
>> A little Googling shows that the IF I mentioned was called the 
>> "arithmetic IF".
> 
> Ah yes.  It was in FORTRAN II, as I recall.

It turns out the original FORTRAN (manual published in October 1956; code first shipped around April 1957) included the arithmetic IF as well as the assigned and computed GOTO statements — see chapter 4 of this manual:

J.W. Backus, R.J. Beeber, S. Best, R. Goldberg, H.L. Herrick, R.A. Hughes, L.B. Mitchell, R.A. Nelson, R. Nutt, D. Sayre, P.B. Sheridan, H. Stern, I. Ziller. The FORTRAN Automatic Coding System for the IBM 704 EDPM : Programmer's Reference Manual. Applied Science Division and Programming Research Department, International Business Machines Corporation, October 15, 1956, 51 pages.
http://www.bitsavers.org/pdf/ibm/704/704_FortranProgRefMan_Oct56.pdf

(For more on the original FORTRAN compiler, see http://www.softwarepreservation.org/projects/FORTRAN/.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20170813/0d2baa3d/attachment.html>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [TUHS] origin of string.h and ctype.h
  2017-08-14  0:02 ` Paul McJones
@ 2017-08-14 16:09   ` Paul Winalski
  2017-08-14 17:16     ` Paul McJones
  2017-08-15  0:37     ` Dave Horsfall
  0 siblings, 2 replies; 18+ messages in thread
From: Paul Winalski @ 2017-08-14 16:09 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1520 bytes --]

On 8/13/17, Paul McJones <paul at mcjones.org> wrote:
> On Sun, 13 Aug 2017, Dave Horsfall wrote:
>
>> On Sat, 12 Aug 2017, Steve Johnson wrote:
>>
>>> A little Googling shows that the IF I mentioned was called the
>>> "arithmetic IF".
>>
>> Ah yes.  It was in FORTRAN II, as I recall.

The FORTRAN II arithmetic IF, with its three-way branch, was probably
introduced to facilitate use of the conditional branch instructions of
the IBM 704, which test the value of the accumulator and take a branch
accordingly:

    TMI (transfer on minus)
    TMP (transfer on plus)
    TZE (transfer on zero)
    TNZ (transfer on not zero)

It takes at most two of these instructions to implement the arithmetic IF.

-Paul W.
>
> It turns out the original FORTRAN (manual published in October 1956; code
> first shipped around April 1957) included the arithmetic IF as well as the
> assigned and computed GOTO statements — see chapter 4 of this manual:
>
> J.W. Backus, R.J. Beeber, S. Best, R. Goldberg, H.L. Herrick, R.A. Hughes,
> L.B. Mitchell, R.A. Nelson, R. Nutt, D. Sayre, P.B. Sheridan, H. Stern, I.
> Ziller. The FORTRAN Automatic Coding System for the IBM 704 EDPM :
> Programmer's Reference Manual. Applied Science Division and Programming
> Research Department, International Business Machines Corporation, October
> 15, 1956, 51 pages.
> http://www.bitsavers.org/pdf/ibm/704/704_FortranProgRefMan_Oct56.pdf
>
> (For more on the original FORTRAN compiler, see
> http://www.softwarepreservation.org/projects/FORTRAN/.)


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [TUHS] origin of string.h and ctype.h
  2017-08-14 16:09   ` Paul Winalski
@ 2017-08-14 17:16     ` Paul McJones
  2017-08-15  3:57       ` Greg 'groggy' Lehey
  2017-08-15  0:37     ` Dave Horsfall
  1 sibling, 1 reply; 18+ messages in thread
From: Paul McJones @ 2017-08-14 17:16 UTC (permalink / raw)


> On Aug 14, 2017, at 9:09 AM, Paul Winalski <paul.winalski at gmail.com> wrote:
> 
>>> ...
> 
> The FORTRAN II arithmetic IF, with its three-way branch, was probably
> introduced to facilitate use of the conditional branch instructions of
> the IBM 704, which test the value of the accumulator and take a branch
> accordingly:
> 
>    TMI (transfer on minus)
>    TMP (transfer on plus)
>    TZE (transfer on zero)
>    TNZ (transfer on not zero)
> 
> It takes at most two of these instructions to implement the arithmetic IF.

And the 709 added CAS (compare accumulator with storage): it skips 0, 1, or 2 instructions depending on whether the contents of the accumulator are algebraically greater, equal, or less than the contents of the referenced memory location. (See page 49 of http://www.bitsavers.org/pdf/ibm/709/709_RefMan_Fortran.pdf.)


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [TUHS] origin of string.h and ctype.h
  2017-08-14 16:09   ` Paul Winalski
  2017-08-14 17:16     ` Paul McJones
@ 2017-08-15  0:37     ` Dave Horsfall
  1 sibling, 0 replies; 18+ messages in thread
From: Dave Horsfall @ 2017-08-15  0:37 UTC (permalink / raw)


On Mon, 14 Aug 2017, Paul Winalski wrote:

[ Ye olde 704 ]

>    TMP (transfer on plus)

That's rather an odd mnemonic...

-- 
Dave Horsfall DTM (VK2KFU)  "Those who don't understand security will suffer."


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [TUHS] origin of string.h and ctype.h
  2017-08-14 17:16     ` Paul McJones
@ 2017-08-15  3:57       ` Greg 'groggy' Lehey
  2017-08-15  4:13         ` Paul McJones
  0 siblings, 1 reply; 18+ messages in thread
From: Greg 'groggy' Lehey @ 2017-08-15  3:57 UTC (permalink / raw)


On Monday, 14 August 2017 at 10:16:57 -0700, Paul McJones wrote:
>> On Aug 14, 2017, at 9:09 AM, Paul Winalski <paul.winalski at gmail.com> wrote:
>>
>>>> ...
>>
>> The FORTRAN II arithmetic IF, with its three-way branch, was probably
>> introduced to facilitate use of the conditional branch instructions of
>> the IBM 704, which test the value of the accumulator and take a branch
>> accordingly:
>>
>>    TMI (transfer on minus)
>>    TMP (transfer on plus)

My reference says TPL.

>>    TZE (transfer on zero)
>>    TNZ (transfer on not zero)
>>
>> It takes at most two of these instructions to implement the arithmetic IF.
>
> And the 709 added CAS (compare accumulator with storage): it skips
> 0, 1, or 2 instructions depending on whether the contents of the
> accumulator are algebraically greater, equal, or less than the
> contents of the referenced memory location.

It was my understanding that the 704 had this instruction too, and
that it was almost certainly the background for arithmetic IF.
Unfortunately, no reference I can find can confirm or deny this
supposition.  Another one is http://www.quadibloc.com/comp/cp0309.htm,
which compares the instruction sets, but it's not categorical enough
for my liking.  But if I interpret it correctly, CAS was implemented
on the 704.

Do you see a proof of the contrary?

In passing, my document also mentions the Honeywell 516, better known
to Unix people as IMP.  It, too, had a CAS-like instruction.

Greg
--
Sent from my desktop computer.
Finger grog at lemis.com for PGP public key.
See complete headers for address and phone numbers.
This message is digitally signed.  If your Microsoft mail program
reports problems, please read http://lemis.com/broken-MUA
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 163 bytes
Desc: not available
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20170815/d5060e11/attachment.sig>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [TUHS] origin of string.h and ctype.h
  2017-08-15  3:57       ` Greg 'groggy' Lehey
@ 2017-08-15  4:13         ` Paul McJones
  0 siblings, 0 replies; 18+ messages in thread
From: Paul McJones @ 2017-08-15  4:13 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1078 bytes --]

On Aug 14, 2017, at 8:57 PM, Greg 'groggy' Lehey <grog at lemis.com> wrote:

> It was my understanding that the 704 had this instruction [CAS] too, and
> that it was almost certainly the background for arithmetic IF.
> Unfortunately, no reference I can find can confirm or deny this
> supposition.  Another one is http://www.quadibloc.com/comp/cp0309.htm,
> which compares the instruction sets, but it's not categorical enough
> for my liking.  But if I interpret it correctly, CAS was implemented
> on the 704.
> 
> Do you see a proof of the contrary?

It turns out CAS is used in many places in the source code of the 4K and 8K drum versions of the final IBM 704 FORTRAN II compiler. See http://www.softwarepreservation.org/projects/FORTRAN/index.html#Source_code; in particular:

Transcribed source: http://www.softwarepreservation.org/projects/FORTRAN/source/fortran-ii/fort1.asm.html
Assembly listing: http://www.softwarepreservation.org/projects/FORTRAN/source/fortran-ii/fort1.lst.html

I didn’t try to figure out if this code generates CAS, but it certainly uses it.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [TUHS] origin of string.h and ctype.h
       [not found] <mailman.1.1502762401.21962.tuhs@minnie.tuhs.org>
@ 2017-08-15  3:06 ` Paul McJones
  0 siblings, 0 replies; 18+ messages in thread
From: Paul McJones @ 2017-08-15  3:06 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 342 bytes --]

On Tue, 15 Aug 2017, Dave Horsfall <dave at horsfall.org> wrote:

>> On Mon, 14 Aug 2017, Paul Winalski wrote:
>> 
>> [ Ye olde 704 ]
>> 
>>>   TMP (transfer on plus)
>> 
> That's rather an odd mnemonic…

Actually, the 704 manual of operation gives the mnemonic as TPL:

http://www.bitsavers.org/pdf/ibm/704/24-6661-2_704_Manual_1955.pdf



^ permalink raw reply	[flat|nested] 18+ messages in thread

* [TUHS] origin of string.h and ctype.h
  2017-08-13  4:26   ` Dave Horsfall
  2017-08-13  5:27     ` Steve Johnson
@ 2017-08-14 11:08     ` Mutiny 
  1 sibling, 0 replies; 18+ messages in thread
From: Mutiny  @ 2017-08-14 11:08 UTC (permalink / raw)


libc.strcmp() behaves similar.From: Dave Horsfall &lt;dave at horsfall.org&gt;Sent: Sun, 13 Aug 2017 09:57:47To: The Eunuchs Hysterical Society &lt;tuhs at tuhs.org&gt;Subject: Re: [TUHS] origin of string.h and ctype.hOn Sat, 12 Aug 2017, Steve Johnson wrote:&gt; Don&#39;t have much to add except to note that early FORTRANs had a version&gt; of IF that took three statement numbers and did a (gasp) GOTO to the&gt; first if the expression in the IF was negative, to the second if it was&gt; 0, and to the third if it was positive. &nbsp; &nbsp;And some mainframes had an&gt; instruction that did exactly that as well...Wasn&#39;t that the computed GOTO?--Dave Horsfall DTM (VK2KFU) &nbsp;&quot;Those who don&#39;t understand security will suffer.&quot;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20170814/daf2e10d/attachment.html>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [TUHS] origin of string.h and ctype.h
  2017-08-13 17:24         ` Warner Losh
@ 2017-08-13 18:23           ` Steve Nickolas
  0 siblings, 0 replies; 18+ messages in thread
From: Steve Nickolas @ 2017-08-13 18:23 UTC (permalink / raw)


On Sun, 13 Aug 2017, Warner Losh wrote:

> It was still in Fortran 77.
>
> N=3
> goto (10, 20, 30, 40, 50), N
>
> would goto label 30.

Reminds me of Microsoft Basic... ON N GOTO 10, 20, 30, 40, 50

-uso.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [TUHS] origin of string.h and ctype.h
  2017-08-13  5:43       ` Dave Horsfall
@ 2017-08-13 17:24         ` Warner Losh
  2017-08-13 18:23           ` Steve Nickolas
  0 siblings, 1 reply; 18+ messages in thread
From: Warner Losh @ 2017-08-13 17:24 UTC (permalink / raw)


On Sat, Aug 12, 2017 at 11:43 PM, Dave Horsfall <dave at horsfall.org> wrote:

> On Sat, 12 Aug 2017, Steve Johnson wrote:
>
> A little Googling shows that the IF I mentioned was called the "arithmetic
>> IF".
>>
>
> Ah yes.  It was in FORTRAN II, as I recall.


Yes. It originated there.

 There was also a Computed GOTO that branched to one of N labels
>> depending on the value of the expression.
>>
>
> I think that was still in FORTRAN IV?


It was still in Fortran 77.

N=3
goto (10, 20, 30, 40, 50), N

would goto label 30.

 And an Assigned GOTO whose main use, as I remember, was to allow for error
>> recovery when a subroutine failed...
>>
>
> A real ugly statement; you assigned a statement number to a variable, then
> did a sort of indirect GOTO (or did the compiler recognise "GOTO I")?
>
> How those poor devils ever debugged their code with such monstrous
> constructions I'll never know.


assign 10 to N
....
goto N

would goto the label 10 in your fortran program. Label 10 must be in the
same compilation unit, and can't be in the middle of a block.

You could make this one better by giving a list of possible statements. I
saw it used effectively when one of N sub formulas was needed later in a
computation in some code doing a complex computations that used it to avoid
division by zero and also optimize the terms used in part of the
calculation. I've also seen it in some truly horrific code too terrible to
relate. But it was relatively rare in the FORTRAN code I dealt with back in
the day...

What made it not totally horrific was that N had to be assigned a label
that was in the functional unit (so it wasn't arbitrary).

If you'd seen some of the spaghetti FORTRAN code I have, you'd know that
these weren't the worst offenders for making things unreadable nightmares,
though they didn't help.

Warner
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20170813/0a21e94b/attachment-0001.html>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [TUHS] origin of string.h and ctype.h
  2017-08-13  5:27     ` Steve Johnson
  2017-08-13  5:43       ` Dave Horsfall
@ 2017-08-13  8:42       ` arnold
  1 sibling, 0 replies; 18+ messages in thread
From: arnold @ 2017-08-13  8:42 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1459 bytes --]

Ah yes, the arithmetic if.  Long ago, I wrote a short paper in the style of
"real programmers don't use pascal" defending the arithmetic if and
encouraging its adoption in newer languages. (All tongue in cheek, of
course.)

For fun, I found it, and put it up at www.skeeve.com/if.pdf.

Enjoy,

Arnold

"Steve Johnson" <scj at yaccman.com> wrote:

> A little Googling shows that the IF I mentioned was called the
> "arithmetic IF".   There was also a Computed GOTO that branched to
> one of N labels depending on the value of the expression.   And an
> Assigned GOTO whose main use, as I remember, was to allow for error
> recovery when a subroutine failed...
>
> Steve 
>
> ----- Original Message -----
> From: "Dave Horsfall" <dave at horsfall.org>
> To:"The Eunuchs Hysterical Society" <tuhs at tuhs.org>
> Cc:
> Sent:Sun, 13 Aug 2017 14:26:53 +1000 (EST)
> Subject:Re: [TUHS] origin of string.h and ctype.h
>
>  On Sat, 12 Aug 2017, Steve Johnson wrote:
>
>  > Don't have much to add except to note that early FORTRANs had a
> version 
>  > of IF that took three statement numbers and did a (gasp) GOTO to
> the 
>  > first if the expression in the IF was negative, to the second if it
> was 
>  > 0, and to the third if it was positive.   And some mainframes had
> an 
>  > instruction that did exactly that as well...
>
>  Wasn't that the computed GOTO?
>
>  -- 
>  Dave Horsfall DTM (VK2KFU) "Those who don't understand security will
> suffer."
>



^ permalink raw reply	[flat|nested] 18+ messages in thread

* [TUHS] origin of string.h and ctype.h
  2017-08-13  5:27     ` Steve Johnson
@ 2017-08-13  5:43       ` Dave Horsfall
  2017-08-13 17:24         ` Warner Losh
  2017-08-13  8:42       ` arnold
  1 sibling, 1 reply; 18+ messages in thread
From: Dave Horsfall @ 2017-08-13  5:43 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 775 bytes --]

On Sat, 12 Aug 2017, Steve Johnson wrote:

> A little Googling shows that the IF I mentioned was called the 
> "arithmetic IF".

Ah yes.  It was in FORTRAN II, as I recall.

> There was also a Computed GOTO that branched to one of N labels
> depending on the value of the expression.

I think that was still in FORTRAN IV?

> And an Assigned GOTO whose main use, as I remember, was to allow for 
> error recovery when a subroutine failed...

A real ugly statement; you assigned a statement number to a variable, then 
did a sort of indirect GOTO (or did the compiler recognise "GOTO I")?

How those poor devils ever debugged their code with such monstrous 
constructions I'll never know.

-- 
Dave Horsfall DTM (VK2KFU)  "Those who don't understand security will suffer."


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [TUHS] origin of string.h and ctype.h
  2017-08-13  4:26   ` Dave Horsfall
@ 2017-08-13  5:27     ` Steve Johnson
  2017-08-13  5:43       ` Dave Horsfall
  2017-08-13  8:42       ` arnold
  2017-08-14 11:08     ` Mutiny 
  1 sibling, 2 replies; 18+ messages in thread
From: Steve Johnson @ 2017-08-13  5:27 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1216 bytes --]


A little Googling shows that the IF I mentioned was called the
"arithmetic IF".   There was also a Computed GOTO that branched to
one of N labels depending on the value of the expression.   And an
Assigned GOTO whose main use, as I remember, was to allow for error
recovery when a subroutine failed...

Steve 

----- Original Message -----
From: "Dave Horsfall" <dave@horsfall.org>
To:"The Eunuchs Hysterical Society" <tuhs at tuhs.org>
Cc:
Sent:Sun, 13 Aug 2017 14:26:53 +1000 (EST)
Subject:Re: [TUHS] origin of string.h and ctype.h

 On Sat, 12 Aug 2017, Steve Johnson wrote:

 > Don't have much to add except to note that early FORTRANs had a
version 
 > of IF that took three statement numbers and did a (gasp) GOTO to
the 
 > first if the expression in the IF was negative, to the second if it
was 
 > 0, and to the third if it was positive.   And some mainframes had
an 
 > instruction that did exactly that as well...

 Wasn't that the computed GOTO?

 -- 
 Dave Horsfall DTM (VK2KFU) "Those who don't understand security will
suffer."

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20170812/262ac1a8/attachment.html>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [TUHS] origin of string.h and ctype.h
  2017-08-13  3:39 ` Steve Johnson
@ 2017-08-13  4:26   ` Dave Horsfall
  2017-08-13  5:27     ` Steve Johnson
  2017-08-14 11:08     ` Mutiny 
  0 siblings, 2 replies; 18+ messages in thread
From: Dave Horsfall @ 2017-08-13  4:26 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 502 bytes --]

On Sat, 12 Aug 2017, Steve Johnson wrote:

> Don't have much to add except to note that early FORTRANs had a version 
> of IF that took three statement numbers and did a (gasp) GOTO to the 
> first if the expression in the IF was negative, to the second if it was 
> 0, and to the third if it was positive.   And some mainframes had an 
> instruction that did exactly that as well...

Wasn't that the computed GOTO?

-- 
Dave Horsfall DTM (VK2KFU)  "Those who don't understand security will suffer."


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [TUHS] origin of string.h and ctype.h
  2017-08-13  1:58 Doug McIlroy
@ 2017-08-13  3:39 ` Steve Johnson
  2017-08-13  4:26   ` Dave Horsfall
  0 siblings, 1 reply; 18+ messages in thread
From: Steve Johnson @ 2017-08-13  3:39 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3174 bytes --]


Don't have much to add except to note that early FORTRANs had a
version of IF that took three statement numbers and did a (gasp) GOTO
to the first if the expression in the IF was negative, to the second
if it was 0, and to the third if it was positive.   And some
mainframes had an instruction that did exactly that as well...

Steve

----- Original Message -----
From: "Doug McIlroy" <doug@cs.dartmouth.edu>
To:<tuhs at minnie.tuhs.org>
Cc:
Sent:Sat, 12 Aug 2017 21:58:19 -0400
Subject:[TUHS] origin of string.h and ctype.h

 Jon Steinhart <jon at fourwinds.com> asked this question (not on tuhs).
 It highlights some less well known contributors to research Unix.

 > I'm trying to find out who came up with strcmp and the idea of
 > returning -1,0,1 for a string comparison. I can see that it's not
in
 > my V6 manual but is in V7. Don't see anything in Algol, PL/I, BCPL,
or B

 The -1,0,1 return from comparisons stems from the interface of qsort,
 which was written by Lee McMahon. As far as I know, the interface for
 the comparison-function parameter originated with him, but
conceivably
 he borrowed it from some other sort utility. The
negative-zero-positive
 convention for the return value encouraged (and perhaps was motivated
by)
 this trivial comparison function for integers
 int compar(a,b) { return(a-b); }
 This screws up on overflow, so cautious folks would write it with
 comparisons. And -1,0,1 were the easiest conventional values to
return:
 int compar(a,b) {
 if(a<b) return(-1);
 if(a>b) return(1);
 return(0);
 }
 qsort was in v2. In v3 a string-comparison routine called "compar"
 appeared, with a man page titled "string comparison for sort". So the
 convention was established early on.

 Compar provided the model for strcmp, one of a package of basic
string
 operations that came much later, in v7, under the banner of string.h
 and ctype.h.

 These packages were introduced at the urging of Nils-Peter Nelson, a
 good friend of the Unix lab, who was in the Bell Labs comp center.
 Here's the story in his own words.

 I wrote a memo to dmr with some suggestions for additions to C. I
asked
 for the str... because the mainframes had single instructions to
implement
 them. I know for sure I had a blindingly fast implementation of
isupper,
 ispunct, etc. I had a table of length 128 integers for the ascii
character
 set; I assigned bits for upper, lower, numeric, punct, control, etc.
So
 ispunct(c) became

 #define PUNCT 0400
 return(qtable[c]&PUNCT)
 instead of
 if(c==':' || c ==';' || ...
 [or
 switch(c) {
 default:
 return 0;
 case ':':
 case ';':
 ...
 return 1;
 }
 MDM]
 dmr argued people could easily write their own but when I showed
 him my qtable was 20 times faster he gave in. I also asked for type
 logical which dmr implemented as unsigned, which was especially
useful
 when bitfields were implemented (a 2 bit int would have values -2,
-1,
 0, 1 instead of 0, 1, 2, 3). I requested a way to interject
assembler,
 which became asm() (yes, a bad idea).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20170812/c5568a90/attachment.html>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [TUHS] origin of string.h and ctype.h
@ 2017-08-13  1:58 Doug McIlroy
  2017-08-13  3:39 ` Steve Johnson
  0 siblings, 1 reply; 18+ messages in thread
From: Doug McIlroy @ 2017-08-13  1:58 UTC (permalink / raw)


Jon Steinhart <jon at fourwinds.com> asked this question (not on tuhs).
It highlights some less well known contributors to research Unix.

> I'm trying to find out who came up with strcmp and the idea of
> returning -1,0,1 for a string comparison.  I can see that it's not in
> my V6 manual but is in V7.  Don't see anything in Algol, PL/I, BCPL, or B

The -1,0,1 return from comparisons stems from the interface of qsort,
which was written by Lee McMahon. As far as I know, the interface for
the comparison-function parameter originated with him, but conceivably
he borrowed it from some other sort utility. The negative-zero-positive
convention for the return value encouraged (and perhaps was motivated by)
this trivial comparison function for integers
	int compar(a,b) { return(a-b); }
This screws up on overflow, so cautious folks would write it with
comparisons. And -1,0,1 were the easiest conventional values to return:
	int compar(a,b) {
		if(a<b) return(-1);
		if(a>b) return(1);
		return(0);
	}
qsort was in v2. In v3 a string-comparison routine called "compar"
appeared, with a man page titled "string comparison for sort". So the
convention was established early on.

Compar provided the model for strcmp, one of a package of basic string
operations that came much later, in v7, under the banner of string.h
and ctype.h.

These packages were introduced at the urging of Nils-Peter Nelson, a
good friend of the Unix lab, who was in the Bell Labs comp center.
Here's the story in his own words.

I wrote a memo to dmr with some suggestions for additions to C.  I asked
for the str... because the mainframes had single instructions to implement
them. I know for sure I had a blindingly fast implementation of isupper,
ispunct, etc. I had a table of length 128 integers for the ascii character
set; I assigned bits for upper, lower, numeric, punct, control, etc. So
ispunct(c) became

	#define PUNCT 0400
	return(qtable[c]&PUNCT)
instead of
	if(c==':' || c ==';' || ...
[or
	switch(c) {
		default:
			return 0;
		case ':':
		case ';':
		...
		return 1;
	}
MDM]
dmr argued people could easily write their own but when I showed
him my qtable was 20 times faster he gave in.  I also asked for type
logical which dmr implemented as unsigned, which was especially useful
when bitfields were implemented (a 2 bit int would have values -2, -1,
0, 1 instead of 0, 1, 2, 3).  I requested a way to interject assembler,
which became asm() (yes, a bad idea).


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2017-08-15  4:13 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <mailman.919.1502645045.3779.tuhs@minnie.tuhs.org>
2017-08-13 21:55 ` [TUHS] origin of string.h and ctype.h Johnny Billquist
2017-08-13 22:26   ` Charles Anthony
2017-08-14  0:02 ` Paul McJones
2017-08-14 16:09   ` Paul Winalski
2017-08-14 17:16     ` Paul McJones
2017-08-15  3:57       ` Greg 'groggy' Lehey
2017-08-15  4:13         ` Paul McJones
2017-08-15  0:37     ` Dave Horsfall
     [not found] <mailman.1.1502762401.21962.tuhs@minnie.tuhs.org>
2017-08-15  3:06 ` Paul McJones
2017-08-13  1:58 Doug McIlroy
2017-08-13  3:39 ` Steve Johnson
2017-08-13  4:26   ` Dave Horsfall
2017-08-13  5:27     ` Steve Johnson
2017-08-13  5:43       ` Dave Horsfall
2017-08-13 17:24         ` Warner Losh
2017-08-13 18:23           ` Steve Nickolas
2017-08-13  8:42       ` arnold
2017-08-14 11:08     ` Mutiny 

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).