guyblade.com #/


PSN
Gamercard


2009 Oct 17 harle


Guy Blade Guy Blade---03:40:00


Limited means worthless
Ada's type system is such that some types are considered limited. In C++ context, these types would have a private operator= function or similar. The net result is that these types cannot be assigned. If you had a limited integer type, for instance, you couldn't say that i := 4. Such a statement would be a compile-time error. Of course, you wouldn't declare an integer a limited type; you would use it for complex object that have internal state information that you don't want being copied without some thought going on (though in C++, that thought should be expressed in the operator= function). This is all well and good, except that the File_Type type is defined as limited. The best analog that I can make to the File_Type is that it seems similar to the C stdio FILE* construct. It is set by using an open operation and is a required argument to all IO calls.

In the C context, something that you do commonly when you have variadic ways of doing IO is to pass around these FILE* constructs rather than passing file names. The reason for this is very straightforward: it gives you more options. For instance, suppose you have a program that can either take a file to act upon or it can read from standard input. The nominal way to do this in C is to check to see if there is a target file defined on the command line. If it is, you set your FILE* pointer to be the result of an fopen operation. If it isn't, you set your FILE* pointer to instead be the predefined variable stdin which corresponds to standard input. Everything is nicely abstracted away and you do your reading from whatever source is appropriate. This concept is great for flexibility and many other languages adopt it, though often in ways that allow you to not worry about the details of pointer mechanics or that apply whatever programming model they use (even Scheme uses a similar model calling the FILE* standin a "port").

Unforuntately, because the File_Type is defined as limited, it seems as though a variable of File_Type cannot be assigned to be Standard_Output. At least, I've been unable to determine how one might make such an assignment. The Ada spec for the various IO packages specify a function called Standard_Output that returns a File_Type which should correspond to the obvious, but since File_Type is limited it seems that the returned variable can't actually be assigned to a variable. I would guess that I could use the function call as an argument to another function directly, but that seems pointless since the default values of the various file io operations default to stdin/stdout as appropriate. Maybe I just haven't found the right incantation yet, but regardless, the fact that a magic incantation is required represents a serious design flaw.

Published by XPostcurses


Permalink to this post     Com/0


2009 Oct 16 yuffie


Guy Blade Guy Blade---20:49:00


Racine Carree
I've talked in the past about the problems that I have with the Ada programming language. I thought may days of fighting with it had come to an end as we'd found a work around that made it so that we didn't need to use the Ada code (written and commented in French) we'd been provided in order to do our processing. A week or so ago, I found out that getting the Ada code working was required for a validation task that is apparently my responsibility. As such, I'm fighting with Ada again. After running the code again for the first time in a year, it returned the familiar "ERREUR_CALCUL"--Calculation Error--a wonderfully vague thing. Digging around led me to find that Ada does have some ways to examine exceptions. Most notably, you can use Ada.Exceptions.Exception_Information to get a filename and line number where the original exception occured. This led me to the function RACINE_CARREE--a 139 line long function--where the original error was occuring. Scanning over the function gave me no help (even though it happened to have comments written in English), but Google Translate told me that racine carree means square root. My first reaction was "Why is the square root failing?" which I quickly saw was because it is apparently being passed a number less than zero. My second reaction was "It takes over 100 lines to implement a square root function?". Ada has a square root built into the language spec. Also, a Newton's method implementation should be like 10 lines even in the tarpit that is Ada.

Regardless, I now have to figure out what impolite function is calling the square root with negative numbers...

Published by XPostcurses


Permalink to this post     Com/0

Archive
Copyright 2002-2024 Blade Libergnosis//Powered By Blogger