comp.lang.ada
 help / color / mirror / Atom feed
* I just found that funny...
@ 1996-04-05  0:00 Jean-Pierre Rosen
  1996-04-06  0:00 ` Robert Dewar
  0 siblings, 1 reply; 3+ messages in thread
From: Jean-Pierre Rosen @ 1996-04-05  0:00 UTC (permalink / raw)


Recently, I needed a function that, given a month, would return the last day
of the month. Since I like things that look nice in named notation, I
(inadvertantly) wrote the  spec  as:

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;

:-)
+------------------------------------o-------------------------------------+
| P-mail:                            | E-mail: rosen@enst.fr               |
|   ADALOG - 27 avenue de Verdun     |    Tel: +33 1 46 45 51 12           |
|   92170 Vanves - FRANCE            |    Fax: +33 1 46 45 52 49           |
+------------------------------------o-------------------------------------+




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

* Re: I just found that funny...
  1996-04-05  0:00 I just found that funny Jean-Pierre Rosen
@ 1996-04-06  0:00 ` Robert Dewar
  1996-04-06  0:00   ` Michael Feldman
  0 siblings, 1 reply; 3+ messages in thread
From: Robert Dewar @ 1996-04-06  0:00 UTC (permalink / raw)


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.





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

* Re: I just found that funny...
  1996-04-06  0:00 ` Robert Dewar
@ 1996-04-06  0:00   ` Michael Feldman
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Feldman @ 1996-04-06  0:00 UTC (permalink / raw)


In article <dewar.828788858@schonberg>, Robert Dewar <dewar@cs.nyu.edu> wrote:

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

[snip]

>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

Now, now, Robert. Careful readers of the notorious programs you referred
to, with their upper-cased RESERVED WORDS, would know that the FUNCTION
would also be named

    LastDay

:-)

On a more serious note, GNAT's "learning" the lexical style of
the programmer, and using it to make better guesses at errors, is
extremely clever.

Mike Feldman




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

end of thread, other threads:[~1996-04-06  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-04-05  0:00 I just found that funny Jean-Pierre Rosen
1996-04-06  0:00 ` Robert Dewar
1996-04-06  0:00   ` Michael Feldman

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