[SPAM] - Re: [GAP] Question about subprogram syntax - Email found in subject

Ted Baker baker at cs.fsu.edu
Tue Feb 21 17:14:58 CET 2006


This is indeed a feature.  In addition to the example with
constants below, Ada treats enumeration literals as parameterless
functions.

On the other hand, I guess it would present to parsing problems to
extend the syntax to allow (but not require) empty parentheses on
function calls without parameters.

A harder question from students is why Ada used parentheses for
array indexing, as compared to [].  The two historical reasons I
know are the Pascal precedent and the idea that an array index
expression A(I) might be replaced later by a pointer-returning
function call without recoding uses.  The latter works OK for
expressions like A(I).Some_Field, where A could be an array of
records or a function returning a pointer to a record.

On the other hand, Ada did not follow through in contexts where an
expression is used as an L-value, including assignment statements
and parameter passing. So, you can't write "A(I) := X;" if A is a
function that returns a pointer.  That pretty well nullifies the
supposed benefit of being able to interchange arrays and
pointer-returning functions.  So, given arrays and functions are
semantically distinct, why make this clear by a syntactic
distinction?

A similar question arises as to the use of ()'s for aggregate
expression versus {}'s, since it creates an ambiguity for
aggregate values with a single element.

These issues are all rather unimportant, though.  You can find just
as many (more) syntactic blemishes in C and its children.

--Ted

On Tue, Feb 21, 2006 at 10:36:30AM -0500, Peter C. Chapin wrote:
> 
> On Tue, 21 Feb 2006, Diego Alonso C?ceres wrote:
> 
> >I've been teaching Ada for three years now and often my students make me 
> >the same question: "Why don't parameter-less subprograms have empty 
> >brackets like C or Java? The code would be easier to read and maintain. 
> >It would be also possible to have a variable and a procedure with the 
> >same name."
> >
> >I really don't what to answer because I think the same. Wasn't Ada 
> >thought as "write once, read many times" or "Ada enhances readability"? 
> >Why inherit this from Pascal?
> 
> I'm not an expert but my understanding was that this is considered a 
> feature. The idea is that it is possible to replace a constant with a 
> parameterless function without editing any code that uses that constant.
> 
> 	A := B;
> 
> B might be a value today, but a parameterless function tomorrow. This 
> might be useful, for example, when it becomes necessary to do some 
> significant computation to obtain the desired value.
> 
> I don't know how often this actually comes up in the wild, though.
> 
> Peter

> _______________________________________________
> GAP mailing list
> GAP at gnat.info
> /no-more-mailman.html
> To unsubscribe from this list, please contact the GAP GNAT Tracker administrator
> within your organization.


More information about the GAP mailing list