Re: No call for Ada (was Re: Announcing new scripting/prototyping language)
From: Ludovic Brenta (ludovic.brenta_at_insalien.org)
Date: 02/09/04
- Next message: Blue Ocean: "Problem with String.split(Regex arg)"
- Previous message: jova: "Re: array to linklist"
- In reply to: MSG: "Re: No call for Ada (was Re: Announcing new scripting/prototyping language)"
- Next in thread: Rob Thorpe: "Re: No call for Ada (was Re: Announcing new scripting/prototyping language)"
- Reply: Rob Thorpe: "Re: No call for Ada (was Re: Announcing new scripting/prototyping language)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 09 Feb 2004 02:24:58 +0100
msg1825@yahoo.com (MSG) writes:
> Martin Krischik <krischik@users.sourceforge.net> wrote:
>
> > Others did that allready. Besides, you would need an installed Ada compiler
> > to verify anyway.
>
> time apt-get install gnat
> => 15 seconds
Thanks, I made that package :)
> > >
> > > Can you do the following in Ada:
> > >
> > > 1. Write *one* bubble-sort function that will work on different
> > > types given an appropriate comparison function
> >
> > Shure you can. Ada invented templates long bevore C++ was even though of.
> > Ada templates are far more powerfull then C++.
>
> Example?
I gave one earlier on c.l.ada. I did not cross-post it to the other
newsgroups.
Ada templates are superior to C++ templates in several respects. For
one thing, you can pass procedures and functions as generic
parameters, and the generic formal parameters specify the signature
for them. Another thing is that the generic formal parameters can
specify several kinds of restrictions to types that are acceptable.
> > > 2. If B is a subtype of A, can you pass it to any function that
> > > takes A as an argument? (covariance)
> >
> > subtype as in object orientation:
> >
> > type Parent is tagged null record;
> > type Child is new Parent with null record;
>
> "null record" ? How about non-null ones? Is a 3D point (x, y, z) a
> subtype of a 2D one (x, y) ?
type Point_2D is tagged record
X, Y : Float;
end record;
type Point_3D is new Point_2D with record
Z : Float;
end record;
> BTW, does Ada have discriminated unions? (if you don't know what they
> are, probably none of the language you used had them)
Yes, they are called variant records.
> Also, is it possible to corrupt memory in Ada?
Yes, if you try hard enough and use Unchecked_Conversion and
System.Address instead of the more usual stuff. Very hard in
practice. I once tried to do a buffer overflow in Ada, and managed
it, but the code to achieve this is rather ugly. Basically, you have
to go the extra mile to corrupt memory in Ada.
> Is it possible to leak memory in Ada?
Yes, just like in C. However, since Ada programmers do much less
dynamic memory allocation, this happens much less often than it does
in C. Note that there also exists a garbage collector in Ada, as part
of AdaCL.
> > or subtype as in simple types:
> >
> > type Day_of_Month is range 1 .. 31;
> > subtype Day_of_Febuary is Day_of_Month range 1 .. 29;
>
> That's neat.
If this is neat then dig this:
for J in Day_Of_Month loop
exit when Month = February and then J >= Day_Of_February'Last;
Put_Line (Day_Of_Month'Image (J));
end loop;
And think about the implications of these ranges on subprograms that
accept only a small set of integer constants as a parameter:
type Assessment is (Yes, No, Maybe, Maybe_Not);
procedure P (A : Assessment);
which is not possible in C:
typedef enum { YES, NO, MAYBE, MAYBE_NOT } assessment_t;
void P (assessment_t A) { }
int main () {
P (42); // no compiler check!
return 0;
}
I just tried the above with gcc -Wall and got no warning. This means
that only a human carefully reviewing this program will see the
mistake (you may also try lint, but this is a tool external to the
language and based on heuristics, not language rules). By contrast,
the Ada compiler catches the mistake automatically in seconds and
leaves you with the confidence that 100% of your code has been
screened for such stupid mistakes.
-- Ludovic Brenta.
- Next message: Blue Ocean: "Problem with String.split(Regex arg)"
- Previous message: jova: "Re: array to linklist"
- In reply to: MSG: "Re: No call for Ada (was Re: Announcing new scripting/prototyping language)"
- Next in thread: Rob Thorpe: "Re: No call for Ada (was Re: Announcing new scripting/prototyping language)"
- Reply: Rob Thorpe: "Re: No call for Ada (was Re: Announcing new scripting/prototyping language)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|