Re: Parsing functions - do I need a keyword like 'def' to indicate a function?

Dave Thompson <david.thompson1@worldnet.att.net>
2 Nov 2004 12:10:00 -0500

          From comp.compilers

Related articles
[7 earlier articles]
Re: Parsing functions - do I need a keyword like 'def' to indicate a f lars@bearnip.com (2004-10-17)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f codeworker@free.fr (2004-10-17)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f zhouhui@wam.umd.edu (Hui Zhou) (2004-10-17)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f postmaster@paul.washington.dc.us (Paul Robinson) (2004-10-21)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f angagon@earthlink.net (Matt O'Connor) (2004-10-30)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f alexc@TheWorld.com (Alex Colvin) (2004-11-02)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f david.thompson1@worldnet.att.net (Dave Thompson) (2004-11-02)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f clint@0lsen.net (Clint Olsen) (2004-11-06)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f kenrose@tfb.com (Ken Rose) (2004-11-14)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f kers@hplb.hpl.hp.com (Chris Dollin) (2004-11-17)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f david.thompson1@worldnet.att.net (Dave Thompson) (2004-11-28)
| List of all articles for this month |
From: Dave Thompson <david.thompson1@worldnet.att.net>
Newsgroups: comp.compilers
Date: 2 Nov 2004 12:10:00 -0500
Organization: AT&T Worldnet
References: 04-10-092 04-10-161
Keywords: syntax, design
Posted-Date: 02 Nov 2004 12:10:00 EST

On 21 Oct 2004 22:31:31 -0400, Paul Robinson
<postmaster@paul.washington.dc.us> wrote:


> M Cleary wrote:
> > ruby and python use "def"
> So does Lisp.


And classic BASIC for statement functions: DEF FNA(X)=X+3


LISP has several defining-words _beginning with_ DEF (DEFUN, DEFMACRO,
DEFCONSTANT, etc.) but I don't recall any using just DEF, and the only
reference I have to hand (a copy of the CommonLISP "Hyperspec"
downloaded from somewhere) certainly doesn't.


> > perl uses "sub"
> So does Visual Basic.
> > lua uses "function"
> So do C, Visual Basic, Pascal and Fortran.


C uses the term but not the keyword. OTOH Ada does.


The others do so only for valued routines; nonvalued ones are 'sub' in
VB, 'subroutine' in Ftn, 'procedure' in Pascal and Ada. But statement
functions in Fortran have no keyword, and in fact are a bit tricky to
disambiguate even for humans.


> > tcl uses "proc"
> So does PL/I.


PL/I actually used either full 'procedure' or abbreviation 'proc'. In
the days of 71-column-usable cards people did tend to abbreviate.


JCL <G><G> also used PROC although IIRC it had to be the first record
(line) in a procedure so the keyword was actually redundant.


<snip>
> You merely need something which either preceeds or follows one or the
> other to differentiate between [definition and use] ...
> The use of a flag on both define of a subroutine and when the subroutine
> is called comes from older languages where we did not have good theory
> on how to analyze language strings properly, i.e. Fortran, which was


Nonvalued SUBROUTINE + CALL yes, but not for valued FUNCTION.


> originally created in the late 1950s. Later languages - even COBOL
> which first came out only a short time later, eliminated defining a
> procedure. You just named it; you called it through PERFORM.


Not really; in classic COBOL a paragraph or section name had to begin
in columns 2-5 and an executable statement had to be in columns 6-up.
Threre was no keyword but there was a hard syntactic distinction. I
believe -85 relaxed this, or at least some -85 compilers I used did.


- David.Thompson1 at worldnet.att.net


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.