I am writing a preprocessor for D that can add new syntaxes to D,
and have implemented noreturn statement that basically throws
an exception
int func(int x)
{
if(x>0){}
else if(x<0){}
noreturn;
//or noreturn("Some message");
}
and another iterating construct i call each, It is used like this:
int[] numbers;
(each numbers)++;
and translated to
for(int index=0;index<numbers.length; index++)
{
numbers[index]++;
}
You can also specify an index:
(each[int i] numbers) = i*i;
===
for(int i=0;i<numbers.length; i++)
{
numbers[i]=i*i;
}
Or use it in function calls
writef("\n",(each numbers));
But now my brain has stopped and i can't figure out how
this should work for a multidimensional case?
int[][] a; //initialized somwhere
sum += (each[int x,int y] a);
//or should it be each[int y,int x]
This should translate to what?
for(int y=0;y<a.length; y++)
{
for(int x=0;x<a[y].length;x++)
{
sum+= a[x][y];
}
}
Is this correct or did i get the indexes wrong? Should x and y
be the other way around? Comments?

Cool, so I'm not the only one, I've done a preprocessor in Python to
allow for some aspect oriented programming yet it's very limited ATM and
kinda slowish (gonna rewrite in D and add functionality).
I hope these 'modifications' can eventually find their way in D 2.0

But now my brain has stopped and i can't figure out how
this should work for a multidimensional case?
int[][] a; //initialized somwhere
sum += (each[int x,int y] a);
//or should it be each[int y,int x]

Are you sure this should be done like this for more than 1 dimension ? I
think it would be relatively simple to do sth like
int[][] a;
sum += (each(each a));
or something along these lines :]
Tom

Cool, so I'm not the only one, I've done a preprocessor in Python to
allow for some aspect oriented programming yet it's very limited ATM and
kinda slowish (gonna rewrite in D and add functionality).

Cool! Isn't it great how people all over the world can get simillar
ideas!

I hope these 'modifications' can eventually find their way in D 2.0

I'm not hoping for anything like this, just playing around, although
it would be very nice.

But now my brain has stopped and i can't figure out how
this should work for a multidimensional case?
int[][] a; //initialized somwhere
sum += (each[int x,int y] a);
//or should it be each[int y,int x]

Are you sure this should be done like this for more than 1 dimension ? I
think it would be relatively simple to do sth like
int[][] a;
sum += (each(each a));

Well, it looks nice but it would break how things work :(
I only expect one each in a statement, so it will generate
a loop for only th first each and some strange looking code.

I'm not hoping for anything like this, just playing around, although
it would be very nice.

I think your preprocessor idea is a great way for experimenting with

syntactical forms.

I thought so too. :) But I am not sure if preprocessor is the right word
because it sound like C preprocessor, but it is actually parsing code

creating the syntax tree with which i am playing.

Technically, that would be called a 'translator'. RATFOR and Cfront are
particularly famous examples of the genre.

Thanks, translator is the word i have been looking for. I have to add that
D is a great language to translate to. Thanks for that!
BTW: I am not that great at understanding licenses, and i was wondering
if the license would permit translating D's lexer to D and changing it to
fit my needs? (The lexer i use is really idiotic)

BTW: I am not that great at understanding licenses, and i was wondering
if the license would permit translating D's lexer to D and changing it to
fit my needs? (The lexer i use is really idiotic)

With respect to that...
awhile ago, I wrote a little Python script to convert a certain subset
of C++ (that which is used by DMD) to D. It handles most everything
I've tested it on. (#ifdef, pointers, arrays, etc)
To use it, just pass the name of the .c/.h pair as an argument, eg:
python c2d.py expression
It will parse expression.c and expression.h, and produce expression.d.
Maybe it will save you some time. :)
<http://andy.tadan.us/d/c2d.py>
-- andy

BTW: I am not that great at understanding licenses, and i was wondering
if the license would permit translating D's lexer to D and changing it

fit my needs? (The lexer i use is really idiotic)

With respect to that...
awhile ago, I wrote a little Python script to convert a certain subset
of C++ (that which is used by DMD) to D. It handles most everything
I've tested it on. (#ifdef, pointers, arrays, etc)
To use it, just pass the name of the .c/.h pair as an argument, eg:
python c2d.py expression
It will parse expression.c and expression.h, and produce expression.d.
Maybe it will save you some time. :)
<http://andy.tadan.us/d/c2d.py>

Thanks. I am sory that i don't have more time so i can explore python
because i have never used it before, so when i do get some free time i think
it will be easier for me to convert Walter's lexer from C++ to D.

BTW: I am not that great at understanding licenses, and i was wondering
if the license would permit translating D's lexer to D and changing it to
fit my needs? (The lexer i use is really idiotic)

With respect to that...
awhile ago, I wrote a little Python script to convert a certain subset
of C++ (that which is used by DMD) to D. It handles most everything
I've tested it on. (#ifdef, pointers, arrays, etc)
To use it, just pass the name of the .c/.h pair as an argument, eg:
python c2d.py expression
It will parse expression.c and expression.h, and produce expression.d.
Maybe it will save you some time. :)
<http://andy.tadan.us/d/c2d.py>
-- andy

Well, Andy's URL is now http://aegisknight.org/~andy/d/, but I'm not sure if
that particular file is there since I'm having trouble reaching his website
right now. I don't know if the server is overloaded or if the server is just
ticked off at me.
If the file isn't at the new website, I should have it burned onto a CD at home.
If I remember, I'll try to find it this weekend.
jcc7

I am writing a preprocessor for D that can add new syntaxes to D,
and have implemented noreturn statement that basically throws
an exception
int func(int x)
{
if(x>0){}
else if(x<0){}
noreturn;
//or noreturn("Some message");
}
and another iterating construct i call each, It is used like this:
int[] numbers;
(each numbers)++;
and translated to
for(int index=0;index<numbers.length; index++)
{
numbers[index]++;
}
You can also specify an index:
(each[int i] numbers) = i*i;
===
for(int i=0;i<numbers.length; i++)
{
numbers[i]=i*i;
}
Or use it in function calls
writef("\n",(each numbers));
But now my brain has stopped and i can't figure out how
this should work for a multidimensional case?
int[][] a; //initialized somwhere
sum += (each[int x,int y] a);
//or should it be each[int y,int x]
This should translate to what?
for(int y=0;y<a.length; y++)
{
for(int x=0;x<a[y].length;x++)
{
sum+= a[x][y];
}
}
Is this correct or did i get the indexes wrong? Should x and y
be the other way around? Comments?

Work on Aspect Oriented development. This would be a nice addition to D.
Regards,
Sjoerd

Or use it in function calls
writef("\n",(each numbers));
But now my brain has stopped and i can't figure out how
this should work for a multidimensional case?
int[][] a; //initialized somwhere
sum += (each[int x,int y] a);
//or should it be each[int y,int x]

I think it would be less confusing if it were "each[int x][int y]"
because comma-separated indices have special meaning in operator
overloading.
Declarations are read from left to right; expressions are read from
right to left. So:
char [x] [y] value;
value [y] [x] = 0;

Or use it in function calls
writef("\n",(each numbers));
But now my brain has stopped and i can't figure out how
this should work for a multidimensional case?
int[][] a; //initialized somwhere
sum += (each[int x,int y] a);
//or should it be each[int y,int x]

I think it would be less confusing if it were "each[int x][int y]"
because comma-separated indices have special meaning in operator
overloading.

I know but i think this is what i tried first and got an ambiguous grammar,
i'll try it again.

Declarations are read from left to right; expressions are read from
right to left. So:
char [x] [y] value;
value [y] [x] = 0;

I am writing a preprocessor for D that can add new syntaxes to D,
and have implemented noreturn statement that basically throws
an exception
int func(int x)
{
if(x>0){}
else if(x<0){}
noreturn;
//or noreturn("Some message");
}
and another iterating construct i call each, It is used like this:
int[] numbers;
(each numbers)++;
and translated to
for(int index=0;index<numbers.length; index++)
{
numbers[index]++;
}
You can also specify an index:
(each[int i] numbers) = i*i;
===
for(int i=0;i<numbers.length; i++)
{
numbers[i]=i*i;
}
Or use it in function calls
writef("\n",(each numbers));
But now my brain has stopped and i can't figure out how
this should work for a multidimensional case?
int[][] a; //initialized somwhere
sum += (each[int x,int y] a);
//or should it be each[int y,int x]
This should translate to what?
for(int y=0;y<a.length; y++)
{
for(int x=0;x<a[y].length;x++)
{
sum+= a[x][y];
}
}
Is this correct or did i get the indexes wrong? Should x and y
be the other way around? Comments?

This is very cool! A substitute for array arith ops till 2.0 maybe :) ? Lots
of other cool uses Im sure.
Where can we get it ?
X