comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: basic basic ada question
Date: Thu, 19 Oct 2006 18:20:38 -0400
Date: 2006-10-19T18:20:38-04:00	[thread overview]
Message-ID: <wcczmbsymkp.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 6WQZg.1028379$084.76409@attbi_s22

"Jeffrey R. Carter" <spam.not.jrcarter@acm.not.spam.org> writes:

> markww wrote:
>> Ok, am I understanding this correctly - if I just '#include" the
>> command line package:
>
> "with" is significantly different from simple text inclusion.

True, but they serve roughly the same purpose, in practise.  For someone
coming from the C world, it's not so bad to think that a package spec is
a cleaner way to do .h files, and "with" is a cleaner way to do
#include.

>...Most of
> what you know from C/++ is wrong for Ada. The sooner you can stop
> thinking in C/++ and start thinking in Ada, the easier you will find it.

Why should one think in C or Ada?  There are lots of concepts that
transcend the languages.  After all, both languages have subroutines,
parameter passing, stack/heap allocation, etc, etc.

>>     with Ada.Command_Line; use Ada.Command_Line;
>
> As a beginner, I would strongly recommend that you avoid "use", at least
> until you understand Ada's visibility rules better.

Probably a good idea.

>> then the package defines the functions:
>>     function Argument_Count return Natural;
>>     function Argument (Number : in Positive) return String;
>> for me which I can use from then on?
>> So in my little app I can just use them like:
>>     Number_Of_Elements := Argument(0);
>> (assuming the 0th argument is the # of elements to allocate...)
>
> As you quoted, Argument's parameter Number has subtype Positive. Zero is
> not a value of Positive. So such a call will raise Constraint_Error. In
> Ada, as in life, we usually count or number things starting from
> 1. Getting away from the low-level, offset-oriented C mindset is part of
> learning to think in Ada.

Well, actually, the first argument is numbered 1 in C, too.  ;-)
argv[0] is what Ada calls Command_Name -- not one of the arguments.

Dijkstra wrote an interesting paper called "Why numbering should start
at zero", which you can find via google.  I don't buy it -- I like to
number most things starting at 1, despite his fairly reasonable
arguments to the contrary.

It's interesting that for enumeration types, T'Pos starts numbering
at 0.

- Bob



  reply	other threads:[~2006-10-19 22:20 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-19 14:30 basic basic ada question markww
2006-10-19 14:47 ` Georg Bauhaus
2006-10-19 15:10   ` markww
2006-10-21 10:29     ` Stephen Leake
2006-10-19 15:11 ` Dmitry A. Kazakov
2006-10-19 15:45   ` markww
2006-10-19 16:29     ` Gautier
2006-10-19 17:16     ` Dmitry A. Kazakov
2006-10-19 20:07     ` Jeffrey R. Carter
2006-10-19 22:20       ` Robert A Duff [this message]
2006-10-20  5:10         ` Jeffrey R. Carter
2006-10-20  7:13           ` Maciej Sobczak
2006-10-20 20:39             ` Jeffrey R. Carter
2006-10-20  7:25       ` Maciej Sobczak
2006-10-20 20:54         ` Jeffrey R. Carter
2006-10-19 21:30 ` James Alan Farrell
2006-10-19 23:03   ` Robert A Duff
2006-10-20  4:54   ` Jeffrey R. Carter
2006-10-20  7:53   ` Dmitry A. Kazakov
2006-10-20  8:17     ` Maciej Sobczak
2006-10-20  9:08       ` Dmitry A. Kazakov
2006-10-20 11:15         ` Maciej Sobczak
2006-10-20 12:19           ` Dmitry A. Kazakov
2006-10-20 12:38             ` Maciej Sobczak
2006-10-20 13:26               ` Dmitry A. Kazakov
2006-10-20 15:29             ` Robert A Duff
2006-10-20 17:37               ` Dmitry A. Kazakov
2006-10-20 20:59                 ` Robert A Duff
2006-10-21 13:39                   ` Dmitry A. Kazakov
2006-10-21 17:53                     ` Robert A Duff
2006-10-22  8:45                       ` Dmitry A. Kazakov
2006-10-23  7:45                     ` Maciej Sobczak
2006-10-23  9:21                       ` Dmitry A. Kazakov
2006-10-23 14:30                         ` Maciej Sobczak
2006-10-23 15:08                           ` Dmitry A. Kazakov
2006-10-23 15:49                             ` Robert A Duff
2006-10-24  7:34                               ` Dmitry A. Kazakov
2006-10-20 19:04           ` Simon Wright
2006-10-20 15:27         ` Robert A Duff
2006-10-20 17:37           ` Dmitry A. Kazakov
2006-10-20 21:00     ` Jeffrey R. Carter
2006-10-21  8:19       ` Dmitry A. Kazakov
2006-10-21 17:32         ` Robert A Duff
2006-10-22  8:45           ` Dmitry A. Kazakov
2006-10-30 11:46             ` Martin Krischik
replies disabled

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