Jump to page: 1 2
Thread overview
bah!
Jul 20, 2002
Andrew Nguyen
Jul 20, 2002
anderson
Jul 20, 2002
C.R.Chafer
Jul 20, 2002
anderson
Jul 20, 2002
Sean L. Palmer
Jul 23, 2002
Sandor Hojtsy
Jul 23, 2002
andrew n
Jul 23, 2002
Pavel Minayev
Jul 23, 2002
OddesE
Jul 25, 2002
Walter
Jul 25, 2002
Pavel Minayev
Jul 20, 2002
Pavel Minayev
Jul 22, 2002
Walter
Jul 22, 2002
pythonnet
Jul 22, 2002
pythonnet
Re: Borland
Jul 22, 2002
Pythonnet
Jul 22, 2002
Pavel Minayev
Jul 22, 2002
Walter
Jul 22, 2002
Pavel Minayev
Jul 23, 2002
anderson
July 20, 2002
I say that arrays should have the []'s at the end of the name. Just like functions. You see, what I see in the C/C++ languages is that the return or data type is at the begiining while any "grouping" symbols are at the end.

For Example,

in C/C++,
int myarray[]; // The array identifier at end
int myfunc(); // Parens denoting a function

Don't get me wrong, I KNOW that you are supposed to have it at the end during normal use.

Also, [][]?
Why not seperate the dimensions with commas? IE,

int my_array[56,23]; /*56*23 array */

just like in functions? You dont see
int my_func(6)("3ghfogho");
do you?
I figure that the co-ordinates are essentialy parameters.
You see, you can also use an array as a function! (Though limited, but
follow along)

Let's say I want a function to compare a variable, foo to a constant qux. It returns 1 if it's higher and 0 if it's lower.

Let's look at this in the ways I've described above:

int qux = 10;

int comparefoo(int foo)
{
 if (foo<qux)
    return 1;
 else(foo=>qux)
    return 0;
}

Now, as an array:

int myarray[1] = {0,1};

Yes, I know, the above wasn't proper D (I still think Mars is cooler) but
still. You get my point?







July 20, 2002
"Andrew Nguyen" <pythonnet@hotmail.com> wrote in message news:aharap$vh2$1@digitaldaemon.com...
> I say that arrays should have the []'s at the end of the name. Just like functions. You see, what I see in the C/C++ languages is that the return
or
> data type is at the begiining while any "grouping" symbols are at the end.
>
> For Example,
>
> in C/C++,
> int myarray[]; // The array identifier at end
> int myfunc(); // Parens denoting a function

D allows for that (although It's not mandatory).

> Don't get me wrong, I KNOW that you are supposed to have it at the end during normal use.
>
> Also, [][]?
> Why not seperate the dimensions with commas? IE,
>
> int my_array[56,23]; /*56*23 array */

That's a good idea.

> just like in functions? You dont see
> int my_func(6)("3ghfogho");
> do you?
> I figure that the co-ordinates are essentialy parameters.
> You see, you can also use an array as a function! (Though limited, but
> follow along)
>
> Let's say I want a function to compare a variable, foo to a constant qux.
It
> returns 1 if it's higher and 0 if it's lower.
>
> Let's look at this in the ways I've described above:
>
> int qux = 10;
>
> int comparefoo(int foo)
> {
>  if (foo<qux)
>     return 1;
>  else(foo=>qux)
>     return 0;
> }
>

Sorry I don't understand? D syntax...

int qux = 10;

int comparefoo(int foo)
{
  if (foo<qux)
     return 1;
  else
     return 0;
}

How about...

int result = cast(int)(foo<qux);

> Now, as an array:
>
> int myarray[1] = {0,1};
>
> Yes, I know, the above wasn't proper D (I still think Mars is cooler) but
> still. You get my point?

Is that ment to be a lookup table (LUT)? How would that work with qux = 10? Or are these examples unrealted?


July 20, 2002
Andrew Nguyen wrote:

> I say that arrays should have the []'s at the end of the name. Just like functions. You see, what I see in the C/C++ languages is that the return or data type is at the begiining while any "grouping" symbols are at the end.
> 
> For Example,
> 
> in C/C++,
> int myarray[]; // The array identifier at end
> int myfunc(); // Parens denoting a function

You can do this in D - int[] myArray; is not a mandatory format, although I
personally find it easier to read (given the choice though I would rather
have 'myArray int[];' [as this makes searching long lists of variable
declarations easier] - but no language is perfect).
At least the D format is consistant if you read it right ...
int[] myArray;  // accessing myArray returns int[]
int myFunc() ...        // accessing myFunc returns int
int[] myFunc2() ...     // accessing myFunc2 returns int[]

> Don't get me wrong, I KNOW that you are supposed to have it at the end during normal use.
> 
> Also, [][]?
> Why not seperate the dimensions with commas? IE,

[][] is used to designate a ragged array.
[,] could be implemented for rectangular arrays.

so.
        int[4][7] array1;       // is 4 ptrs to arrays of int length 7 named array1
                        // (accesses required at least 1 pointer dereference)
        int[4,7] array2;        // is array of width 4, length 7 named array2
                        // (accesses do not require a pointer dereference -
                        //  but do required a multiply / shift and add - though
                        //  these may be optimised away some times)

If the latter is not currently supported I believe it soon should be (v2?).
Also remember we could say
        x = array1[2].length;
How would we do this with your syntax array in a consistant way?
        x = myarray.length[2];  // only (nice) way I can think of (==7)
        x = myarray.length;     // this would return 4 = 1st parameter
        // other wise we just have to be inconsistant
For a rectangular array the dimensions are fixed on initialisation so we
could use
        x = array2.dimension[0];        // return length == 4
        x = array2.dimension[1];        // return width == 7
        x = array2.dimension(1);        // alt syntax - function style (?)
        x = array2.length;              // error "rectangular array - not ragged array"
                                // (or may return length * witdh == 4*7 == 28)
Also this would allow us to do
        int[5][6,7] array3;             // ragged array of rectangular arrays
(though this probably should not be allowed without further investigation :
 ? is it useful
 ? is it a pain to implement (probably)
 ? could it lead to errors
 ? do the implementation costs out weight the benifits
)

> int my_array[56,23]; /*56*23 array */
> 
> just like in functions? You dont see
> int my_func(6)("3ghfogho");
> do you?
> I figure that the co-ordinates are essentialy parameters.
> You see, you can also use an array as a function! (Though limited, but
> follow along)
> 
> Let's say I want a function to compare a variable, foo to a constant qux. It returns 1 if it's higher and 0 if it's lower.
> 
> Let's look at this in the ways I've described above:
> 
> int qux = 10;
> 
> int comparefoo(int foo)
> {
>  if (foo<qux)
>     return 1;
>  else(foo=>qux)

why is the second condition needed on the else?
should this be >= not => anyway?
and why bother with the else at all in this example?

>     return 0;
> }

D ->
int qux = 10;   // probably better as enum if constant
int comparefoo(int foo)
{
        if( foo<qux ) return 1;
        return 0;
}

Or are you trying to give an example of another problem?

> Now, as an array:
> 
> int myarray[1] = {0,1};

D allows this.

int[1] myarray = { 0, 1 };      // also allowed

> Yes, I know, the above wasn't proper D (I still think Mars is cooler) but
> still. You get my point?

As I do not know Mars (other than in it's incarnation as D) I could not comment.

C 2002/7/20
July 20, 2002
"C.R.Chafer" <blackmarlin@nospam.asean-mail.com> wrote in message news:ahbjoc$28ot$1@digitaldaemon.com...
> Andrew Nguyen wrote:

> [][] is used to designate a ragged array.
> [,] could be implemented for rectangular arrays.
>
> so.
>         int[4][7] array1;       // is 4 ptrs to arrays of int length 7
named array1
>                         // (accesses required at least 1 pointer
dereference)
>         int[4,7] array2;        // is array of width 4, length 7 named
array2
>                         // (accesses do not require a pointer
dereference -
>                         //  but do required a multiply / shift and add -
though
>                         //  these may be optimised away some times)

I agree, this makes good sense.


July 20, 2002
On Fri, 19 Jul 2002 22:14:57 -0700 "Andrew Nguyen" <pythonnet@hotmail.com> wrote:

> Also, [][]?
> Why not seperate the dimensions with commas? IE,
> 
> int my_array[56,23]; /*56*23 array */

It makes more sense when applied to dynamic arrays. So, we could have two distinct types, one for arrays of arrays - [][] - and another for rectangular arrays - [,]. Just like C#.

	short[,] screenbuf;

	if (vidmode == VGA50)
		screen = new short[80, 50];
	else
		screen = new short[80, 25];

I don't know a way to do it in D, currently. You can use [][], but then the array won't be stored as a single block in memory, and thus cannot be copied easily. On other hand, rectangular arrays could be copied:

	short[80,25]* screen = cast(short[80,25]*) 0xA0000;
	(*screen)[] = screenbuf[];
July 20, 2002
I like it.  I want this.

Sean

"anderson" <anderson@firestar.com.au> wrote in message news:ahbr09$2g8j$1@digitaldaemon.com...
>
> "C.R.Chafer" <blackmarlin@nospam.asean-mail.com> wrote in message news:ahbjoc$28ot$1@digitaldaemon.com...
> > Andrew Nguyen wrote:
>
> > [][] is used to designate a ragged array.
> > [,] could be implemented for rectangular arrays.
> >
> > so.
> >         int[4][7] array1;       // is 4 ptrs to arrays of int length 7
> named array1
> >                         // (accesses required at least 1 pointer
> dereference)
> >         int[4,7] array2;        // is array of width 4, length 7 named
> array2
> >                         // (accesses do not require a pointer
> dereference -
> >                         //  but do required a multiply / shift and add -
> though
> >                         //  these may be optimised away some times)
>
> I agree, this makes good sense.



July 22, 2002
"Pavel Minayev" <evilone@omen.ru> wrote in message
news:CFN374577734276852@news.digitalmars.com...
It makes more sense when applied to dynamic arrays. So, we could
have two distinct types, one for arrays of arrays - [][] - and
another for rectangular arrays - [,]. Just like C#.


D already supports rectangular arrays - just supply a dimension in the brackets. No need for a separate syntax.


July 22, 2002
In article <ahfot9$4d2$1@digitaldaemon.com>, Walter says...
>
>
>"Pavel Minayev" <evilone@omen.ru> wrote in message
>news:CFN374577734276852@news.digitalmars.com...
>It makes more sense when applied to dynamic arrays. So, we could
>have two distinct types, one for arrays of arrays - [][] - and
>another for rectangular arrays - [,]. Just like C#.
>
>
>D already supports rectangular arrays - just supply a dimension in the brackets. No need for a separate syntax.
>
>


July 22, 2002
In article <ahfot9$4d2$1@digitaldaemon.com>, Walter says...
>
>
>"Pavel Minayev" <evilone@omen.ru> wrote in message
>news:CFN374577734276852@news.digitalmars.com...
>It makes more sense when applied to dynamic arrays. So, we could
>have two distinct types, one for arrays of arrays - [][] - and
>another for rectangular arrays - [,]. Just like C#.
>
>
>D already supports rectangular arrays - just supply a dimension in the brackets. No need for a separate syntax.
>
>

Sorry for the repost, my finger slipped :)

But... couldn't ragged arrays SAVE memory? Like in a string array or something of that sort.


July 22, 2002
(For userfriendly readers.) I am thinkink dat da java bashink was not good idea.
Da?

*tugs at shirt collar* I think Im regretting sending that email to Borland... I kinda bashed Java... IMHO it's a piece of shik. But uh... I don't think it'll stifle my plan of bringing D to the masses. Da?


« First   ‹ Prev
1 2