Re: A[x][y][z]




sterten@xxxxxxx wrote:

> So, who will be the first to write that useful command line utility
> converting occurrances of A[x,y] to A[x][y]...

This would be a simple one-liner in the elegant Snobol language.Sadly,
the references to Snobol that show up
with Google are mostly 6-year old messages, complaining
that Snobol has disappeared!

But this is comp.lang.c not comp.lang.snobol.
Let me try to help OP.

<diatribe>
C is a victim of its own success!

I don't think Fortran programmers ever say
"Let's make our language more like Pascal."
Ones that might ... switch to Pascal!
Similarly, while most consider some languages,
e.g. Forth or APL, to have perverse syntax,
those who go out of their way to use Forth or
APL, almost by definition, like the "perversity"!

But C's rich elegant combination of simplicity
and flexibility and the fact that it was better
suited than prior languages to a wide variety of
applications recommended itself to many expert
programmers in the 1970's and 80's and it soon
become widespread ... even among many who
couldn't appreciate its elegance.

One of the most elegant features of C is the
identity between the referencing of pointers
and array elements. Yet this seems to be
consistently confused by novices! Why? It
can't be that C is "too complicated" -- C is
based on a tiny set of elegant principles.
I think the problem is that novices can't
believe such a powerful language is *so simple*!

One example of such simplicity is the fact, as
Keith Thompson points out, that arrays are always
one-dimensional: a 2-D array is an array of
arrays.

Viewed in total isolation, the question of whether
to start array indexes at 0 or 1 may be a legitimate
open question, but in C the question answers itself
once one notices that the following expressions
(outside sizeof, etc.) must be identical in C:
*p
*(p+0)
0[p+0]
p[0+0]
p[0]
Anyone who suggests that C indexes should start at 1,
doesn't even understand this much: the idea that their
opinion on C might have merit is laughable.

Similarly, since in the 4-D array expression
a[b][c][d][e]
one can't know, without studying the declarations,
whether 'a' is an array of pointers to arrays
of pointers, a pointer to an array of pointers
to arrays, or one of several other possibilities,
the idea of obfuscating this further by writing
a[b,c,d,e]
suggests lack of understanding. (We're sorry if
'[' and ']' are hard to produce on German keyboards
but I'm sure there's workarounds for that.)

(Do any other languages, besides C++ and others that
model their syntax on C, have a similar elegant
array/pointer model?)

Finally, it shows grave confusion to suggest that
someone who prefers to see C syntax when they're reading
a C program should simply run 'cc -E'. We all look
at intermediate compilation results when there's a
reason, but viewing unobfuscated source shouldn't be
one of them. To give only one of the most obvious
objections, on all compilers I've tried 'cc -E' will
remove comments; did OP overlook this?

No one claims the C language is a perfect panacea, but
it has an enviable elegance. Novices should devote
themselves to grasping that elegance before offering
"improvements."
</diatribe>

James Dow Allen

.



Relevant Pages

  • Re: A[x][y][z]
    ... > "Let's make our language more like Pascal." ... > and array elements. ... > based on a tiny set of elegant principles. ... > I think the problem is that novices can't ...
    (comp.lang.c)
  • Re: Permission Denied when using File.Copy or fso.CopyFile
    ... the CIM_DataFile WMI Class. ... filename to an array for later retry. ... It's not the most elegant solution in the world but it's a nice hack ...
    (microsoft.public.scripting.vbscript)
  • Re: Handling freeform date field order
    ... 'PointedEars' Lahn posted: ... I can't think of an elegant modification to get Y M D order. ... rotate an array in either direction and to transpose a pair (adjacent or ...
    (comp.lang.javascript)
  • Re: Multiple arguments for Hash#delete
    ... Though it doesn't matter as much becuase it's ... Simple and elegant. ... when working on this for Array. ...
    (comp.lang.ruby)
  • Re: pointers?
    ... There's absolutely nothing abstract in pointers. ... Take the C array: if you write ... To the assembly language programmers who were the first generation adopters of C, this mental mapping was very tight. ... Forth gained the most traction on machines like the IBM 1130 and the Data General Nova. ...
    (comp.lang.forth)