initializer inside if is already in C++, and it will probably be on C2Y.
Thiago Adams wrote:
initializer inside if is already in C++, and it will probably be on C2Y.
can you show an example how it look like?
what with definition in espression liek
foo((int a=2*int b=10) etc
It loks weird but I also COME TO CONCLUSION TODAY
THAT in new language we must drop the "pure text" text set
we need bold and possibly loloristation so instead
int x = 2
you could just bold x and write =2
bold x = 2
and simply bold mean symbol definition
this opens a new wariety of nice code looking,
by colorisation some coud differentiate if it is int or float
etc
On 20/08/2024 14:18, fir wrote:
Thiago Adams wrote:
initializer inside if is already in C++, and it will probably be on C2Y. >>>
can you show an example how it look like?
#include <stdio.h>
int main()
{
if (FILE* f = fopen("file.txt", "r"); f)
{
/*...*/
fclose(f);
}
if (FILE* f = fopen("file.txt", "r"))
{
/*...*/
fclose(f);
}
}
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3267.htm
https://en.cppreference.com/w/cpp/language/if
got some thought today thet simply probably allowing to define "int a" everywhere could be just simply a good c (or other language) design
decision
initializer inside if is already in C++, and it will probably be on C2Y.
On Tue, 20 Aug 2024 18:48:17 +0200, fir wrote:
got some thought today thet simply probably allowing to define "int a"
everywhere could be just simply a good c (or other language) design
decision
Somehow along the line from BCPL to B to C, one useful feature was lost:
the ability to have a value-returning statement block inside an
expression.
Lawrence D'Oliveiro <ldo@nz.invalid> writes:
On Tue, 20 Aug 2024 18:48:17 +0200, fir wrote:
got some thought today thet simply probably allowing to define "int a"
everywhere could be just simply a good c (or other language) design
decision
Somehow along the line from BCPL to B to C, one useful feature was lost:
the ability to have a value-returning statement block inside an
expression.
It was lost in the BCPL to B transition.
On 21/08/2024 01:42, Blue-Maned_Hawk wrote:
Thiago Adams wrote:
initializer inside if is already in C++, and it will probably be on C2Y.If it's for consistency with how for loops permit declarations, i would
_much_ prefer that they just outlaw that to induce consistency.
(Really, i'd ideally want things to just stay as they are, since
declarations in for loops are simply too useful for macros.)
I like the ability to declare things inside if.
if (FILE* f = fopen("file.txt", "r"))
{
/*...*/
fclose(f);
}
Because it makes the scope of f, associated with the pointed object
lifetime.
For instance, if you try to use f
if (FILE* f = fopen("file.txt", "r"))
{
/*...*/
fclose(f);
}
fwrite(f, ..) ;// ERROR
For this type of error you need my static analyzer. (cake) :D
On 21/08/2024 01:42, Blue-Maned_Hawk wrote:
Thiago Adams wrote:
initializer inside if is already in C++, and it will probably be onIf it's for consistency with how for loops permit declarations, i would
C2Y.
_much_ prefer that they just outlaw that to induce consistency.
(Really, i'd ideally want things to just stay as they are, since
declarations in for loops are simply too useful for macros.)
I like the ability to declare things inside if.
if (FILE* f = fopen("file.txt", "r"))
{
/*...*/ fclose(f);
}
Because it makes the scope of f, associated with the pointed object
lifetime.
For instance, if you try to use f
if (FILE* f = fopen("file.txt", "r"))
{
/*...*/ fclose(f);
}
fwrite(f, ..) ;// ERROR
Thiago Adams wrote:
On 21/08/2024 01:42, Blue-Maned_Hawk wrote:
Thiago Adams wrote:
initializer inside if is already in C++, and it will probably be onIf it's for consistency with how for loops permit declarations, i would
C2Y.
_much_ prefer that they just outlaw that to induce consistency.
(Really, i'd ideally want things to just stay as they are, since
declarations in for loops are simply too useful for macros.)
I like the ability to declare things inside if.
if (FILE* f = fopen("file.txt", "r"))
{
/*...*/ fclose(f);
}
Because it makes the scope of f, associated with the pointed object
lifetime.
For instance, if you try to use f
if (FILE* f = fopen("file.txt", "r"))
{
/*...*/ fclose(f);
}
fwrite(f, ..) ;// ERROR
You can already do that in C23:
if (…) {
FILE * f = fopen("file.txt", "r");
/* … */
fclose(f);
}
fwrite(f, …); /* Some kind of error happens. */
Or, if you need it to exist before the controlling expression:
for (bool x = true; x; x = false) for (FILE * f = fopen("file.txt", "r");
x; x = false) if (…) {
/* … */
fclose(f);
}
fwrite(f, …);
The original code:
if (FILE* f = fopen("file.txt", "r"))
{
/*...*/ fclose(f);
}
doesn't allow for taking some non-trivial action of the fopen() call
fails, but if a declaration in an if condition is visible in the else
clause, you could write something like:
if (FILE* f = fopen("file.txt", "r")) {
/*...*/
fclose(f);
}
else {
perror("file.txt");
exit(EXIT_FAILURE); // or try something else
}
<snip/>
Sometimes, too much syntactic sugar is not good because it creates too
many variants.
What's the significance of the declared name being in scope in the else clause here?
On 2024-08-22, Ben Bacarisse <ben@bsb.me.uk> wrote:
What's the significance of the declared name being in scope in the else
clause here?
else is a part of the if statement. Everything under the statement
should have visibility to its lexical variable(s).
On 22/08/2024 09:40, Blue-Maned_Hawk wrote:
Thiago Adams wrote:
On 21/08/2024 01:42, Blue-Maned_Hawk wrote:
Thiago Adams wrote:
initializer inside if is already in C++, and it will probably be onIf it's for consistency with how for loops permit declarations, i would >>>> _much_ prefer that they just outlaw that to induce consistency.
C2Y.
(Really, i'd ideally want things to just stay as they are, since
declarations in for loops are simply too useful for macros.)
I like the ability to declare things inside if.
if (FILE* f = fopen("file.txt", "r"))
{
/*...*/ fclose(f);
}
Because it makes the scope of f, associated with the pointed object
lifetime.
For instance, if you try to use f
if (FILE* f = fopen("file.txt", "r"))
{
/*...*/ fclose(f);
}
fwrite(f, ..) ;// ERROR
You can already do that in C23:
if (…) {
FILE * f = fopen("file.txt", "r");
/* … */
fclose(f);
}
fwrite(f, …); /* Some kind of error happens. */
Or, if you need it to exist before the controlling expression:
for (bool x = true; x; x = false) for (FILE * f = fopen("file.txt",
"r");
x; x = false) if (…) {
/* … */
fclose(f);
}
fwrite(f, …);
I wonder, if I laid it out it properly:
for (bool x = true; x; x = false)
for (FILE * f = fopen("file.txt", "r"); x; x = false)
if (…) {
/* … */
fclose(f);
}
fwrite(f, …);
Nope; I still haven't the faintest idea what this is supposed to do. I suspect that it doesn't actually run or need those two nested loops.
I assume the (...) tests the value of 'f'? If so then perhaps this is a shorter way of expressing the same thing:
{
FILE * f = fopen("file.txt", "r");
if (f) {
/* … */
fclose(f);
}
}
fwrite(f, …);
Bart wrote:
btw maybe not so much relevent as what you write but
if to think the convention
foir(int i=0; i<100; i++)
{
//,,,
}
to amke int i scope relevant to only inner of the loop seem just
logically wrong
On 23/08/2024 11:47, fir wrote:
Bart wrote:
btw maybe not so much relevent as what you write but
if to think the convention
foir(int i=0; i<100; i++)
{
//,,,
}
to amke int i scope relevant to only inner of the loop seem just
logically wrong
Actually it's one of the few places it makes sense!
But I don't like this idiom for several reasons. Sure, it can be
convenient to write:
for(int i=0; i<100; i++)
without having to make an annoying detour to the top of the function to
write that declaration for i. But then you need a second loop, and a
third, and how you have to repeat a declaration each time:
for(int i=0; i<200; i++)
Better to do it once and forget about it.
Then, it allows nested loops like this:
for (int i = 0; i<A; ++i)
for (int i = 0; i<B; ++i)
for (int i = 0; i<C; ++i)
All those i's are different! Only the last is accessible in the inner loop.
Bart wrote:
On 23/08/2024 11:47, fir wrote:i never used nor even seen this with 3 i..for me as i said "loop" iteslf
Bart wrote:
btw maybe not so much relevent as what you write but
if to think the convention
foir(int i=0; i<100; i++)
{
//,,,
}
to amke int i scope relevant to only inner of the loop seem just
logically wrong
Actually it's one of the few places it makes sense!
But I don't like this idiom for several reasons. Sure, it can be
convenient to write:
for(int i=0; i<100; i++)
without having to make an annoying detour to the top of the function to
write that declaration for i. But then you need a second loop, and a
third, and how you have to repeat a declaration each time:
for(int i=0; i<200; i++)
Better to do it once and forget about it.
Then, it allows nested loops like this:
for (int i = 0; i<A; ++i)
for (int i = 0; i<B; ++i)
for (int i = 0; i<C; ++i)
All those i's are different! Only the last is accessible in the inner
loop.
not neccessary belongs to inside of the loop more like the outside..
here liek this this is misleading that the i is one thing - until
someone knows its just internat thing (but i as i said disagree it
should be intennal)
On Tue, 20 Aug 2024 18:48:17 +0200, fir wrote:
got some thought today thet simply probably allowing to define "int a"
everywhere could be just simply a good c (or other language) design
decision
Somehow along the line from BCPL to B to C, one useful feature was lost:
the ability to have a value-returning statement block inside an
expression.
Lawrence D'Oliveiro wrote:
Somehow along the line from BCPL to B to C, one useful feature wasif so thats probably sad, though i dont know how it looked like
lost: the ability to have a value-returning statement block inside an
expression.
Lawrence D'Oliveiro wrote:
On Sun, 25 Aug 2024 12:40:39 +0200, fir wrote:
Lawrence D'Oliveiro wrote:
Somehow along the line from BCPL to B to C, one useful feature wasif so thats probably sad, though i dont know how it looked like
lost: the ability to have a value-returning statement block inside an
expression.
The construct looks like
VALOF $( ... «stmts»; RESULTIS «return-value» $)
it is good to things return value and good to be able to combine it
as i sait for example i consider such loops
10'x //ten tiem execute x
print (10'x+=x)/10
would be equivalent of
for(int i=0; i<10; i++) x+=x;
print(x/10)
(and its still c, just with shorted syntax not python et sort)
On Sun, 25 Aug 2024 12:40:39 +0200, fir wrote:
Lawrence D'Oliveiro wrote:
Somehow along the line from BCPL to B to C, one useful feature wasif so thats probably sad, though i dont know how it looked like
lost: the ability to have a value-returning statement block inside an
expression.
The construct looks like
VALOF $( ... «stmts»; RESULTIS «return-value» $)
fir wrote:
Lawrence D'Oliveiro wrote:
On Sun, 25 Aug 2024 12:40:39 +0200, fir wrote:
Lawrence D'Oliveiro wrote:
Somehow along the line from BCPL to B to C, one useful feature wasif so thats probably sad, though i dont know how it looked like
lost: the ability to have a value-returning statement block inside an >>>>> expression.
The construct looks like
VALOF $( ... «stmts»; RESULTIS «return-value» $)
it is good to things return value and good to be able to combine it
as i sait for example i consider such loops
10'x //ten tiem execute x
print (10'x+=x)/10
would be equivalent of
for(int i=0; i<10; i++) x+=x;
print(x/10)
(and its still c, just with shorted syntax not python et sort)
as to this loop as i said i had no ide how to make indexes like i
in this form but what comes to my mind now is maybe something lika
10'print("x")
10i'print(i)
480y' 640x' set_pixel(x,y, 0xffff00)
those i,x,y in loop 'headers' could be possibly subscripted
like 2 in typical H20 (2 is subscripted
eventually one can go
10' print((x 0)++)
where x 0 is initialisation of int x to zero
fir wrote:
fir wrote:
Lawrence D'Oliveiro wrote:
On Sun, 25 Aug 2024 12:40:39 +0200, fir wrote:
Lawrence D'Oliveiro wrote:
Somehow along the line from BCPL to B to C, one useful feature was >>>>>> lost: the ability to have a value-returning statement block inside an >>>>>> expression.if so thats probably sad, though i dont know how it looked like
The construct looks like
VALOF $( ... «stmts»; RESULTIS «return-value» $)
it is good to things return value and good to be able to combine it
as i sait for example i consider such loops
10'x //ten tiem execute x
print (10'x+=x)/10
would be equivalent of
for(int i=0; i<10; i++) x+=x;
print(x/10)
(and its still c, just with shorted syntax not python et sort)
as to this loop as i said i had no ide how to make indexes like i
in this form but what comes to my mind now is maybe something lika
10'print("x")
10i'print(i)
480y' 640x' set_pixel(x,y, 0xffff00)
those i,x,y in loop 'headers' could be possibly subscripted
like 2 in typical H20 (2 is subscripted
eventually one can go
10' print((x 0)++)
where x 0 is initialisation of int x to zero
overally not bad, i could somewhat accept that loop
(yu wouldnt belive how hard is come to that syntax conclusions,
literally takes years, and not 5 years more like 15)
fir wrote:
fir wrote:
fir wrote:
Lawrence D'Oliveiro wrote:
On Sun, 25 Aug 2024 12:40:39 +0200, fir wrote:
Lawrence D'Oliveiro wrote:
Somehow along the line from BCPL to B to C, one useful feature was >>>>>>> lost: the ability to have a value-returning statement blockif so thats probably sad, though i dont know how it looked like
inside an
expression.
The construct looks like
VALOF $( ... «stmts»; RESULTIS «return-value» $)
it is good to things return value and good to be able to combine it
as i sait for example i consider such loops
10'x //ten tiem execute x
print (10'x+=x)/10
would be equivalent of
for(int i=0; i<10; i++) x+=x;
print(x/10)
(and its still c, just with shorted syntax not python et sort)
as to this loop as i said i had no ide how to make indexes like i
in this form but what comes to my mind now is maybe something lika
10'print("x")
10i'print(i)
480y' 640x' set_pixel(x,y, 0xffff00)
those i,x,y in loop 'headers' could be possibly subscripted
like 2 in typical H20 (2 is subscripted
eventually one can go
10' print((x 0)++)
where x 0 is initialisation of int x to zero
overally not bad, i could somewhat accept that loop
(yu wouldnt belive how hard is come to that syntax conclusions,
literally takes years, and not 5 years more like 15)
its digression but still i got problem what to do with
function definition esp returning values
take for example div(11,5) function which returns 2 (11/5) as
a main result but should also eventually return 1 (11%5) as a second
prt of result
the thinking is now maybe something like that (if using old syntax)
int div( int a, int b)
{
static int result = a/b,
static int remainder = a%b
return result;
}
x = div(20/7); //gives result
x y = (result, remainder) div(20/7); //gives both
x y = (remainder, result) div(20/7); //gives both but in different order
y = (remainder) div(20/7); //gives only the remainder
could also be used to skip a part of results
v2 = (x,y) cross(A,B) //when full result is x y z
also imo a given function if longer could ghave a bumch of local
variables and this way you eventually acces set of some you want so
it may be handy
10' print((x 0)++)
where x 0 is initialisation of int x to zero
overally not bad, i could somewhat accept that loop
(yu wouldnt belive how hard is come to that syntax conclusions,
literally takes years, and not 5 years more like 15)
On Sun, 25 Aug 2024 12:40:39 +0200, fir wrote:
Lawrence D'Oliveiro wrote:
Somehow along the line from BCPL to B to C, one useful feature wasif so thats probably sad, though i dont know how it looked like
lost: the ability to have a value-returning statement block inside an
expression.
The construct looks like
VALOF $( ... «stmts»; RESULTIS «return-value» $)
fir wrote:
fir wrote:
Lawrence D'Oliveiro wrote:
On Sun, 25 Aug 2024 12:40:39 +0200, fir wrote:
Lawrence D'Oliveiro wrote:
Somehow along the line from BCPL to B to C, one useful feature was >>>>>> lost: the ability to have a value-returning statement block inside an >>>>>> expression.if so thats probably sad, though i dont know how it looked like
The construct looks like
VALOF $( ... «stmts»; RESULTIS «return-value» $)
it is good to things return value and good to be able to combine it
as i sait for example i consider such loops
10'x //ten tiem execute x
print (10'x+=x)/10
would be equivalent of
for(int i=0; i<10; i++) x+=x;
print(x/10)
(and its still c, just with shorted syntax not python et sort)
as to this loop as i said i had no ide how to make indexes like i
in this form but what comes to my mind now is maybe something lika
10'print("x")
10i'print(i)
480y' 640x' set_pixel(x,y, 0xffff00)
those i,x,y in loop 'headers' could be possibly subscripted
like 2 in typical H20 (2 is subscripted
eventually one can go
10' print((x 0)++)
where x 0 is initialisation of int x to zero
overally not bad, i could somewhat accept that loop
(yu wouldnt belive how hard is come to that syntax conclusions,
literally takes years, and not 5 years more like 15)
fir wrote:
on fictional snippet (probebly not working)though eventualy it canm be written shorter i guess
void draw_line( float x, float y, float x2, float y2, unsigned color)
{
float
wx=dist(x,x2),wy=dist(y,y2); int m=wx<wy?wx:wy;
float dx=wx/m,dy=wy/m;for(int
i=0;i<(int)m;i++)set_pixel(x+=dx,y+=dy,color);
}
thin skin
draw_line`x`y`x2`y2`color
{
`wx=dist x x2,`wy=dist y y2,`M=(wx<wy?wx!wy)
`dx=wx/m,`dy=wy/m, M'set_pixel x+=dx y+=dy color;
}
draw_line`x`y`x2`y2`color:
`m = min 'wx=abs x2-x 'wy=abs y2-y) ' set_pixel x+=wx/m y+=wy/m color;
;
not to say it lookin specially good but welll..
fir wrote:
fir wrote:
fir wrote:
Lawrence D'Oliveiro wrote:
On Sun, 25 Aug 2024 12:40:39 +0200, fir wrote:
Lawrence D'Oliveiro wrote:
Somehow along the line from BCPL to B to C, one useful feature was >>>>>>> lost: the ability to have a value-returning statement blockif so thats probably sad, though i dont know how it looked like
inside an
expression.
The construct looks like
VALOF $( ... «stmts»; RESULTIS «return-value» $)
it is good to things return value and good to be able to combine it
as i sait for example i consider such loops
10'x //ten tiem execute x
print (10'x+=x)/10
would be equivalent of
for(int i=0; i<10; i++) x+=x;
print(x/10)
(and its still c, just with shorted syntax not python et sort)
as to this loop as i said i had no ide how to make indexes like i
in this form but what comes to my mind now is maybe something lika
10'print("x")
10i'print(i)
480y' 640x' set_pixel(x,y, 0xffff00)
those i,x,y in loop 'headers' could be possibly subscripted
like 2 in typical H20 (2 is subscripted
eventually one can go
10' print((x 0)++)
where x 0 is initialisation of int x to zero
overally not bad, i could somewhat accept that loop
(yu wouldnt belive how hard is come to that syntax conclusions,
literally takes years, and not 5 years more like 15)
i wanted to compore how many chars my thin c skin conventions would
make (but not having funic F for wloat or runic U for unsigned) i put `
and the spare is not great becouse c is quite thin - hovever it uses a
lot of what i call 'decorators i eman not necessary ().; which could
be changed to spaces, it not spares chars but somewhat spares ink
on fictional snippet (probebly not working)
void draw_line( float x, float y, float x2, float y2, unsigned color)
{
float
wx=dist(x,x2),wy=dist(y,y2); int m=wx<wy?wx:wy;
float dx=wx/m,dy=wy/m;for(int i=0;i<(int)m;i++)set_pixel(x+=dx,y+=dy,color);
}
thin skin
draw_line`x`y`x2`y2`color
{
`wx=dist x x2,`wy=dist y y2,`M=(wx<wy?wx!wy)
`dx=wx/m,`dy=wy/m, M'set_pixel x+=dx y+=dy color;
}
fir wrote:
fir wrote:though eventualy it canm be written shorter i guess
fir wrote:
fir wrote:
Lawrence D'Oliveiro wrote:
On Sun, 25 Aug 2024 12:40:39 +0200, fir wrote:
Lawrence D'Oliveiro wrote:
Somehow along the line from BCPL to B to C, one useful feature was >>>>>>>> lost: the ability to have a value-returning statement blockif so thats probably sad, though i dont know how it looked like
inside an
expression.
The construct looks like
VALOF $( ... «stmts»; RESULTIS «return-value» $)
it is good to things return value and good to be able to combine it
as i sait for example i consider such loops
10'x //ten tiem execute x
print (10'x+=x)/10
would be equivalent of
for(int i=0; i<10; i++) x+=x;
print(x/10)
(and its still c, just with shorted syntax not python et sort)
as to this loop as i said i had no ide how to make indexes like i
in this form but what comes to my mind now is maybe something lika
10'print("x")
10i'print(i)
480y' 640x' set_pixel(x,y, 0xffff00)
those i,x,y in loop 'headers' could be possibly subscripted
like 2 in typical H20 (2 is subscripted
eventually one can go
10' print((x 0)++)
where x 0 is initialisation of int x to zero
overally not bad, i could somewhat accept that loop
(yu wouldnt belive how hard is come to that syntax conclusions,
literally takes years, and not 5 years more like 15)
i wanted to compore how many chars my thin c skin conventions would
make (but not having funic F for wloat or runic U for unsigned) i put `
and the spare is not great becouse c is quite thin - hovever it uses a
lot of what i call 'decorators i eman not necessary ().; which could
be changed to spaces, it not spares chars but somewhat spares ink
on fictional snippet (probebly not working)
void draw_line( float x, float y, float x2, float y2, unsigned color)
{
float
wx=dist(x,x2),wy=dist(y,y2); int m=wx<wy?wx:wy;
float dx=wx/m,dy=wy/m;for(int
i=0;i<(int)m;i++)set_pixel(x+=dx,y+=dy,color);
}
thin skin
draw_line`x`y`x2`y2`color
{
`wx=dist x x2,`wy=dist y y2,`M=(wx<wy?wx!wy)
`dx=wx/m,`dy=wy/m, M'set_pixel x+=dx y+=dy color;
}
draw_line`x`y`x2`y2`color:
`m = min 'wx=abs x2-x 'wy=abs y2-y) ' set_pixel x+=wx/m y+=wy/m color;
;
not to say it lookin specially good but welll..
On 27/08/2024 19:44, fir wrote:
fir wrote:
on fictional snippet (probebly not working)though eventualy it canm be written shorter i guess
void draw_line( float x, float y, float x2, float y2, unsigned color)
{
float
wx=dist(x,x2),wy=dist(y,y2); int m=wx<wy?wx:wy;
float dx=wx/m,dy=wy/m;for(int
i=0;i<(int)m;i++)set_pixel(x+=dx,y+=dy,color);
}
thin skin
draw_line`x`y`x2`y2`color
{
`wx=dist x x2,`wy=dist y y2,`M=(wx<wy?wx!wy)
`dx=wx/m,`dy=wy/m, M'set_pixel x+=dx y+=dy color;
}
draw_line`x`y`x2`y2`color:
`m = min 'wx=abs x2-x 'wy=abs y2-y) ' set_pixel x+=wx/m y+=wy/m color;
;
not to say it lookin specially good but welll..
There are ways to have more compact syntax without it turning weird,
leaving out types, and using backtick separators and other strange punctuation (or is that lone ')' a typo?).
Start with this version:
void draw_line( float x, float y, float x2, float y2, unsigned color)
{
float
wx=dist(x,x2),wy=dist(y,y2); int m=wx<wy?wx:wy;
float dx=wx/m,dy=wy/m;for(inti=0;i<(int)m;i++)set_pixel(x+=dx,y+=dy,color);
}
For example:
void draw_line(f32 x, y, x2, y2; u32 colour) {
f32 wx = dist(x, y2), wy = dist(y, y2)
int m = min(wx, wy)
repeat m {
set_pixel(x += wx/m, y += wy/m, colour)
}
}
Summary:
- Allow shared types in parameter lists
- Auto semicolon insertion
- Built-in 'min/max' operators
- New repeat-n-times loop
- Shorter type names
Bart wrote:
On 27/08/2024 19:44, fir wrote:
fir wrote:
on fictional snippet (probebly not working)though eventualy it canm be written shorter i guess
void draw_line( float x, float y, float x2, float y2, unsigned color)
{
float
wx=dist(x,x2),wy=dist(y,y2); int m=wx<wy?wx:wy;
float dx=wx/m,dy=wy/m;for(int
i=0;i<(int)m;i++)set_pixel(x+=dx,y+=dy,color);
}
thin skin
draw_line`x`y`x2`y2`color
{
`wx=dist x x2,`wy=dist y y2,`M=(wx<wy?wx!wy)
`dx=wx/m,`dy=wy/m, M'set_pixel x+=dx y+=dy color;
}
draw_line`x`y`x2`y2`color:
`m = min 'wx=abs x2-x 'wy=abs y2-y) ' set_pixel x+=wx/m y+=wy/m color; >>> ;
not to say it lookin specially good but welll..
There are ways to have more compact syntax without it turning weird,
leaving out types, and using backtick separators and other strange
punctuation (or is that lone ')' a typo?).
Start with this version:
void draw_line( float x, float y, float x2, float y2, unsigned color)
{
float
wx=dist(x,x2),wy=dist(y,y2); int m=wx<wy?wx:wy;
float
dx=wx/m,dy=wy/m;for(inti=0;i<(int)m;i++)set_pixel(x+=dx,y+=dy,color);
}
For example:
void draw_line(f32 x, y, x2, y2; u32 colour) {
f32 wx = dist(x, y2), wy = dist(y, y2)
int m = min(wx, wy)
repeat m {
set_pixel(x += wx/m, y += wy/m, colour)
}
}
Summary:
- Allow shared types in parameter lists
- Auto semicolon insertion
- Built-in 'min/max' operators
- New repeat-n-times loop
- Shorter type names
yes there were typos and mistakes
its more like
draw_line`x1`y1`x2`y2`color:
`m = min abs x2-x1 abs y2-y1 ' set_pixel x1+=(x2-x1)/m y1+=(y2-y1)/m color;
;
with some 'cheats as i both float and unsigned gere note by ` but ascii
has to narow charset amd i dont know unicode enough (though probably i
could look into unicode and chose some
• draw_line`x1`y1`x2`y2`color:
`m= x2‾x1 ˩ y2‾y1 ' set_pixel x1+=(x2-x1)/m y1+=(y2-y1)/m color;
•
fir wrote:
Bart wrote:
On 27/08/2024 19:44, fir wrote:
fir wrote:
on fictional snippet (probebly not working)though eventualy it canm be written shorter i guess
void draw_line( float x, float y, float x2, float y2, unsigned color) >>>>> {
float
wx=dist(x,x2),wy=dist(y,y2); int m=wx<wy?wx:wy;
float dx=wx/m,dy=wy/m;for(int
i=0;i<(int)m;i++)set_pixel(x+=dx,y+=dy,color);
}
thin skin
draw_line`x`y`x2`y2`color
{
`wx=dist x x2,`wy=dist y y2,`M=(wx<wy?wx!wy)
`dx=wx/m,`dy=wy/m, M'set_pixel x+=dx y+=dy color;
}
draw_line`x`y`x2`y2`color:
`m = min 'wx=abs x2-x 'wy=abs y2-y) ' set_pixel x+=wx/m y+=wy/m
color;
;
not to say it lookin specially good but welll..
There are ways to have more compact syntax without it turning weird,
leaving out types, and using backtick separators and other strange
punctuation (or is that lone ')' a typo?).
Start with this version:
void draw_line( float x, float y, float x2, float y2, unsigned color) >>> {
float
wx=dist(x,x2),wy=dist(y,y2); int m=wx<wy?wx:wy;
float
dx=wx/m,dy=wy/m;for(inti=0;i<(int)m;i++)set_pixel(x+=dx,y+=dy,color);
}
For example:
void draw_line(f32 x, y, x2, y2; u32 colour) {
f32 wx = dist(x, y2), wy = dist(y, y2)
int m = min(wx, wy)
repeat m {
set_pixel(x += wx/m, y += wy/m, colour)
}
}
Summary:
- Allow shared types in parameter lists
- Auto semicolon insertion
- Built-in 'min/max' operators
- New repeat-n-times loop
- Shorter type names
yes there were typos and mistakes
its more like
draw_line`x1`y1`x2`y2`color:
`m = min abs x2-x1 abs y2-y1 ' set_pixel x1+=(x2-x1)/m y1+=(y2-y1)/m
color;
;
with some 'cheats as i both float and unsigned gere note by ` but ascii
has to narow charset amd i dont know unicode enough (though probably i
could look into unicode and chose some
• draw_line`x1`y1`x2`y2`color:
`m= x2‾x1 ˩ y2‾y1 ' set_pixel x1+=(x2-x1)/m y1+=(y2-y1)/m color;
•
there are some unicode characters that could be handy for example this
bullet ••••• above is good
this ˩ ˩ ˩ ˩ ˩ is also ok ...i would need probably to chose somethink like 20-30 potentially best to add - but today my eyesight quite bad so
some other day
Lawrence D'Oliveiro wrote:
On Sun, 25 Aug 2024 12:40:39 +0200, fir wrote:
Lawrence D'Oliveiro wrote:
Somehow along the line from BCPL to B to C, one useful feature was
lost: the ability to have a value-returning statement block inside an >>>> expression.
if so thats probably sad, though i dont know how it looked like
The construct looks like
VALOF $( ... <<stmts>>; RESULTIS <<return-value>> $)
So a la GNUC's statement-expressions? I've heard talks that C2y is likely
to be the revision that adds lambdas to C[1], so perhaps we'll get it back? over half a century later.
?
[1]In addition to subsuming statement-expressions, this would also subsume multiple other extensions, particularly GCC's local functions and Clang's Blocks.
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
[...]
Not exactly. There are things that can be done inside a
statement-expression that are not available inside nested
functions or lambdas.
And you're not going to tell us what those things are.
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
[...]
Not exactly. There are things that can be done inside a
statement-expression that are not available inside nested
functions or lambdas.
And you're not going to tell us what those things are.
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
[...]
Not exactly. There are things that can be done inside a
statement-expression that are not available inside nested
functions or lambdas.
And you're not going to tell us what those things are.
Apparently not.
But one thing occurs to me... you can break (or jump) out of a statement expression:
for (int i = 0; i < 10; i++)
printf("%d\n", ({ if (i > 5) break; i; }));
You can't do this with a lambda or nested function.
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
[...]
Not exactly. There are things that can be done inside a
statement-expression that are not available inside nested
functions or lambdas.
And you're not going to tell us what those things are.
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
[...]
Not exactly. There are things that can be done inside a
statement-expression that are not available inside nested
functions or lambdas.
And you're not going to tell us what those things are.
Let me add something to my last response. I think you're doing
a disservice to the community by always explaining everything
in great detail. Sometimes, sure; perhaps even mostly. But
not always. People need to learn to think. You must have heard
the proverb about giving a man a fish versus teaching a man to
fish. You just keep doling out fish. I want people to learn to
think so they can fish for themselves.
One difference between you and me is that I almost never respond
to a posting of yours that is part of a conversation with someone
else to complain about your answer. And I don't engage in such
behavior even though I think that what you're doing is worse than
what I'm doing. I'm fed up with your high and mighty attitude.
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
[...]
Not exactly. There are things that can be done inside a
statement-expression that are not available inside nested
functions or lambdas.
And you're not going to tell us what those things are.
Let me add something to my last response. I think you're doing
a disservice to the community by always explaining everything
in great detail. Sometimes, sure; perhaps even mostly. But
not always. People need to learn to think. You must have heard
the proverb about giving a man a fish versus teaching a man to
fish. You just keep doling out fish. I want people to learn to
think so they can fish for themselves.
One difference between you and me is that I almost never respond
to a posting of yours that is part of a conversation with someone
else to complain about your answer. And I don't engage in such
behavior even though I think that what you're doing is worse than
what I'm doing. I'm fed up with your high and mighty attitude.
on fictional snippet (probebly not working)
void draw_line( float x, float y, float x2, float y2, unsigned color)
{
float
wx=dist(x,x2),wy=dist(y,y2); int m=wx<wy?wx:wy;
float dx=wx/m,dy=wy/m;for(int
i=0;i<(int)m;i++)set_pixel(x+=dx,y+=dy,color);
}
fir wrote:
on fictional snippet (probebly not working)
void draw_line( float x, float y, float x2, float y2, unsigned color)
{
float
wx=dist(x,x2),wy=dist(y,y2); int m=wx<wy?wx:wy;
float dx=wx/m,dy=wy/m;for(int
i=0;i<(int)m;i++)set_pixel(x+=dx,y+=dy,color);
}
i thought on it yet and concluded code for that shopuld look more like
point {ints x y}
line {points p q}
draw line(color c)
{
point a = p
int m = max abs(q-p) ' a+=(q-p)/m, Setpixel a, c
}
explanation:
point {ints x y}
this is structure "point" definition ,
ints is int[] but it also has named elements so int[0[ is x and int[1]
is y (such is very handy as structure may be seen as array and array as structure.. so more fractal touch added (if it is proper name fractal
touch as maybe not im not sure)
line {points p q}
same this is structure named "line" defined
draw line(color c)
this is function header though line here is a type so its
a bit new in that aspect possibly
point a = p
instantiates point structure entity named a and copies p into it
as p is point in line and p is int2 type and int2 has defined assigning
to other int2 so this is automatic
int m = max abs(q-p)
same here q-p are int2 - int2 they are defined to retuirn int2
abs is defined on int2 to return two int2 values then max is defined
on int2 to return one int
m' is loop (loop m times)
this a+=(q-p)/m, is calculation, i know it will not work as
it shopuld work on floats but for simplicity of example as i was thinkin
on ints i will stay it with ints
overally this is kinda closer to C2 syntax i need
void draw_line(f32 x, y, x2, y2; u32 colour) {
- Allow shared types in parameter lists ...
On Tue, 27 Aug 2024 19:59:13 +0100, Bart wrote:
void draw_line(f32 x, y, x2, y2; u32 colour) {
- Allow shared types in parameter lists ...
A bit easier if you flip it around and use Pascal-style syntax:
procedure draw_line(x, y, x2, y2 : f32; colour : u32)
See how much more natural that is?
On 02/09/2024 04:32, Lawrence D'Oliveiro wrote:
On Tue, 27 Aug 2024 19:59:13 +0100, Bart wrote:
void draw_line(f32 x, y, x2, y2; u32 colour) {
- Allow shared types in parameter lists ...
A bit easier if you flip it around and use Pascal-style syntax:
procedure draw_line(x, y, x2, y2 : f32; colour : u32)
See how much more natural that is?
It becomes a bit less natural when you want to initialise a variable at
the same time, or want define a default value for a parameter.
Pascal didn't allow either of those.
draw_line`x`y`x2`y2`color {
On Mon, 2 Sep 2024 10:53:33 +0100, Bart wrote:
On 02/09/2024 04:32, Lawrence D'Oliveiro wrote:
On Tue, 27 Aug 2024 19:59:13 +0100, Bart wrote:
void draw_line(f32 x, y, x2, y2; u32 colour) {
- Allow shared types in parameter lists ...
A bit easier if you flip it around and use Pascal-style syntax:
procedure draw_line(x, y, x2, y2 : f32; colour : u32)
See how much more natural that is?
It becomes a bit less natural when you want to initialise a variable at
the same time, or want define a default value for a parameter.
Pascal didn't allow either of those.
Ada does, with a very natural extension of the same syntax. Even allows passing arguments by keyword, too.
On Mon, 2 Sep 2024 10:53:33 +0100, Bart wrote:
On 02/09/2024 04:32, Lawrence D'Oliveiro wrote:
On Tue, 27 Aug 2024 19:59:13 +0100, Bart wrote:
void draw_line(f32 x, y, x2, y2; u32 colour) {
- Allow shared types in parameter lists ...
A bit easier if you flip it around and use Pascal-style syntax:
procedure draw_line(x, y, x2, y2 : f32; colour : u32)
See how much more natural that is?
It becomes a bit less natural when you want to initialise a
variable at the same time, or want define a default value for a
parameter.
Pascal didn't allow either of those.
Ada does, with a very natural extension of the same syntax.
Even
allows passing arguments by keyword, too.
Note that even C++ has now had to allow function return types to be specified at the end of the prototype instead of up front, because
type interdependencies don’t work very well otherwise.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 152:40:32 |
Calls: | 10,383 |
Files: | 14,054 |
Messages: | 6,417,821 |