comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@cs.nyu.edu (Robert Dewar)
Subject: Re: I just found that funny...
Date: 1996/04/06
Date: 1996-04-06T00:00:00+00:00	[thread overview]
Message-ID: <dewar.828788858@schonberg> (raw)
In-Reply-To: 199604051600.SAA07609@email.enst.fr

Jean-Pierre complained:

  \ "function Last_Day (Of : Months) return Date;
  \
  \ GNAT appropriately complained that "Of is  a reserved word that cannot be used
  \ as an identifier". So the next thing that sprung to my mind was:
  \
  \ function Last_Day (In : Months) return Date;
  \
  \ Nooooooo ! Think of something else...
  \
  \ function Last_Day (For : Months) return Date;
  \
  \ Arghhhhhhh.... I ended up with:
  \
  \ function Last_Day (Of_Month : Months) return Date;"

Now I would have liked to fix that by doing:

  function Last_Day (Of_ : Months) return Date;

but lots of people turned out to be allergic to trailing underscores. We
got it in for a while, but then the French delegation in particular
absolutely insisted on its removal :-)

Incidentally, this is a nice example on which to demontstrate an interesting
little bit of error handling stuff in GNAT:

     2. function Last_Day (Of : Months) return Date;
                           |
        >>> reserved word "of" cannot be used as identifier

     2. function Last_Day (of : Months) return Date;
                           |
        >>> identifier expected

Note that GNAT guesses by your casing whether you intended to write
an identifier or keyword. Of course it only pays attention to case *if*

Just in case you are Mike Feldman (:-) or someone else who likes to use
some different casing convention:

     2. FUNCTION Last_Day (Of : Months) RETURN Date;
                           |
        >>> reserved word "OF" cannot be used as identifier

     2. FUNCTION Last_Day (OF : Months) RETURN Date;
                           |
        >>> identifier expected

As you see, GNAT learns the style you are using (and also uses this same
style in error messages).

If you are used to programming in a certain one letter language and think
that using different cases for keywords and identifiers is silly :-), then

     2. function last_day (of : months) return date;
                           |
        >>> reserved word "of" cannot be used as identifier

GNAT guessed right in this case, but cannot always do such a good job if
it does not have the extra clue.

Generally you get better error messages out of GNAT if you indent
and layout your code consistently, and if you use a consistent
scheme for differentiating the casing of keywords and identifiers.





  reply	other threads:[~1996-04-06  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-04-05  0:00 I just found that funny Jean-Pierre Rosen
1996-04-06  0:00 ` Robert Dewar [this message]
1996-04-06  0:00   ` Michael Feldman
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox