Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

"He never calls subroutines "functions"; I'm not sure where that usage comes from, but certainly by BASIC and LISP there were "functions" that were at least implemented by subroutines."

I think the early BASIC's used the subroutine nomenclature for GOSUB, where there was no parameter passing or anything, just a jump that automatically remembered the place to return.

Functions in BASIC, as I remember it, were something quite different. I think they were merely named abbreviations for arithmetic expressions and simple one line artithmetic expressions only. They were more similar to very primitive and heavily restricted macros than to subroutines or functions.



Right, that's what Algol-58 functions were, too. I think FORTRAN also has a construct like this, but I forget.


FORTRAN had both functions and subroutines. A function returned a value and was invoked in an expression (eg. S=SIN(A)). A subroutine was invoked by calling it (eg. CALL FOPEN(FNAME, PERMS)).


I should probably just Google this, but how did you define the functions?


    C     -------- START OF FUNCTION -------    
          INTEGER FUNCTION INCREMENT(I)
          INCREMENT=I+1
          RETURN
          END
    C     -------- END OF FUNCTION -------


FORTRAN also had single-expression function definitions, e.g.

    ARGF(X, Y, Z) = (D/E) * Z+ X** F+ Y/G
Naturally this is syntactically identical to an array element assignment, which is one of the many things that made compiling FORTRAN so much fun.


Yeah, that's also almost exactly the same as the Algol-58 syntax for defining such functions. And BASIC, except you had to say

    DEF FNF(X, Y, Z) = (D/E) * Z+ X** F+ Y/G
and the function name had to start with FN.


s/had/has/

In the flang-new compiler, which builds a parse tree for the whole source file before processing any declarations, it was necessary to parse such things as statement functions initially so that further specification statements could follow them. Later, if it turns out that the function name is an array or regular function returning a pointer, the parse tree gets patched up in place and the statement becomes the first executable statement.


Yes, sorry, I didn't mean to imply that Fortran doesn't exist any more. I compiled Fortran on my cellphone as recently as last year.


For those who like that sort of thing, Fortran is exactly the sort of thing that they like.




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

Search: