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

Front Page

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