Re: COMMON structures and text parsing
- From: nospam@xxxxxxxxxxxxx (Richard Maine)
- Date: Sat, 6 Dec 2008 11:11:07 -0800
Ron Shepard <ron-shepard@xxxxxxxxxxxxxxxxxx> wrote:
In article <ghdimf$ok4$1@xxxxxxxxxxxxxxxxxxxxxxxx>, nmm1@xxxxxxxxx
wrote:
Fortran does this better, and always has done. It is a slight extra
complication to have a proper separate type, but makes everything just
SO much cleaner.
The place where this choice is not "cleaner" is when you need to
index into an array using a logical value.
which is not essentially different from indexing an array using any
other type. Sorry, but I like the compiler catching errors such as using
incorrect types for things like that. Any trivial syntactic
inconvenience for the cases where one might imagine want to do things
like that is dwarfed by the improved reliability from having the
compiler diagnose the erroneous cases - at least in my opinion.
Not to speak of the fact that I find the whole business of interpreting
a logical as an integer confusing. In your example, that translates into
me being uncertain which value is first in the array. Maybe it is
"obvious" to you what the true and false values "should" be, or at least
what their ordering is. But it sure isn't obvious to me. No amount of
argument about why one answer "must" be the "correct" one will address
that, because no matter how excellent the argument, that doesn't mean it
is "obvious" to me. It is observed fact that it is not obvious to me,
and if it takes explaining to me, then that, by definition, is not
obvious.
Besides which, I've heard the explanations, and I still don't find it
obvious. It isn't that I don't recall the explanations, but rather that
I recall to many ones that have different results. Explaining what
choice is more convenient in some situations or is somehow more
efficient to implement in hardware doesn't do it. My mind isn't that
hardware.
When I write C code, I'm always having to go check the definition or I
get it wrong a significant fraction of the time. When I read C code, I
just guess which is probably right from context, except when I'm
debugging. When I'm debugging C code.... well.... it just takes me a
darned long time for many reasons, this being just one.
If you really want to do that, Glen showed a solution to your sample
code using the merge intrinsic. I'd say his was a very clean solution,
as that is exactly what the merge intrinsic is; this isn't some arcane
special case of it. Or you could write your own short function to do
whatever you want with any particular type.
Or you could just use the IF version that you showed. Though it takes 5
statements instead of 1, it is almost impossible to misunderstand as
long as the logical_val has a name that well reflects its logical
nature. With that proviso, my mother could read and understand it, and
she doesn't do computers at all; English is quite sufficient and she
does that quite well enough.
Seems to me as though you are looking for something like associative
arrays (I think that's the term), where you can "index" an array with
darn near anything. That can indeed be useful (see several other
languages), but I think it works best if you define the critter in its
own right instead of trying to fake it with a feature that isn't
designed that way. In particular, if the array index is going to be
some type other than integer, you really have that type be the index
instead of somehow faking that type to be interpreted as an integer for
this purpose. You don't then drag along properties of integers that
don't fit. One of those integer properties that you don't drag along is
that of ordering. Integers have a natural order. Logicals do not. If you
do an associative array of logicals and do it "right", then the question
of which logical value is "first" doesn't come up to confuse people like
me.
IMO, things really would have been simpler for fortran to have just
defined integer values for .true. and .false. 40 years ago. Then
neither fortran nor C would be in the situation they are now.
I might say instead that I'm impresed at the foresight shown by
avoiding that and thus keeping the door open for associative arrays to
be done "properly" some day. Of course, I'm sure there was no such
explicit intention, but I think that a "clean" underlying structure that
avoids conflating the concepts of integers and logicals just naturally
makes for a better base even for things that one hasn't explicitly
thought of yet.
--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
.
- Follow-Ups:
- Re: COMMON structures and text parsing
- From: Ron Shepard
- Re: COMMON structures and text parsing
- References:
- COMMON structures and text parsing
- From: Terence
- Re: COMMON structures and text parsing
- From: e p chandler
- Re: COMMON structures and text parsing
- From: Glen Herrmannsfeldt
- Re: COMMON structures and text parsing
- From: nmm1
- Re: COMMON structures and text parsing
- From: Gary Scott
- Re: COMMON structures and text parsing
- From: nmm1
- Re: COMMON structures and text parsing
- From: James Van Buskirk
- Re: COMMON structures and text parsing
- From: nmm1
- Re: COMMON structures and text parsing
- From: Ron Shepard
- COMMON structures and text parsing
- Prev by Date: Re: COMMON structures and text parsing
- Next by Date: Re: COMMON structures and text parsing
- Previous by thread: Re: COMMON structures and text parsing
- Next by thread: Re: COMMON structures and text parsing
- Index(es):
Relevant Pages
|