May 27, 2002
You could almost get rid of if entirely by the use of ?: and creative multiplication with 0.  The hardware doesn't have if, it has test-and-branch.  Conditional goto.  Modern processors don't do if statements so well anyway, they interfere with deep pipelining.  Maybe a new kind of conditional construct would be handy?

Sean

"Martin M. Pedersen" <mmp@www.moeller-pedersen.dk> wrote in message news:acthvu$5b9$1@digitaldaemon.com...
> "Pavel Minayev" <evilone@omen.ru> wrote in message news:actg00$3eo$1@digitaldaemon.com...
>
> >     if (a == b)
> >         c = f(z);
> >     else
> >         c = f(z + 1);
> >
> > No brackets! =)
>
> c = f(z+(a==b));
>
> No if! :-)



May 27, 2002
My apologies.  I was browsing the code in DedicateD and assumed it was your.

Andy

In article <actg00$3eo$1@digitaldaemon.com>, Pavel Minayev says...
>
>"Andy Walker" <Andy_member@pathlink.com> wrote in message news:actfkn$30t$1@digitaldaemon.com...
>
>> I think I code "C" the way Pavel codes it, with lots of brackets:
>> if ( a == b)
>> {
>> c = f(z);
>> }
>> else
>> {
>> c = f(z+1);
>> }
>
>Er... that's exactly the opposite to what I'd write:
>
>    if (a == b)
>        c = f(z);
>    else
>        c = f(z + 1);
>
>No brackets! =)
>
>
>
>


May 27, 2002
>
> I wouldn't mind integrating the various loop structures together
somehow...
> a loop is a loop is a loop.  Oftentimes I find myself wanting a for loop

Maybe it'd be nice to have something like VB. If you want to do this (from
C):

while (cond) {
...
};

you do this (in VB):

do while cond
...
loop

Or like this:

do until not ( cond )
...
loop

(parenthesis aren't mandatory) Or if you want to do this:

do {
...
} while (cond);

You do this:

do
...
loop while cond

Or

do
...
loop until not (cond)

The do..loop construction in VB is really powerful. You can even write:

do
...
loop

To make an infinite loop. Maybe that (or something like that) could be a solution to have loops integrated under a same instruction.


May 28, 2002
Well said. Down with code-heroes. Up with quality.

"Karl Bochert" <kbochert@ix.netcom.com> wrote in message news:1103_1022519110@bose...
> On Mon, 27 May 2002 17:11:37 +0100, "Martin M. Pedersen"
<mmp@www.moeller-pedersen.dk> wrote:
> > "Pavel Minayev" <evilone@omen.ru> wrote in message news:actg00$3eo$1@digitaldaemon.com...
> >
> > >     if (a == b)
> > >         c = f(z);
> > >     else
> > >         c = f(z + 1);
> > >
> > > No brackets! =)
> >
> > c = f(z+(a==b));
> >
> > No if! :-)
> >
> It's called obfuscation. I suppose when a change requred 'z+OFFSET+2' in
the
> else clause you could write
>
>     c = f(z+(a==b)*2 + (a==b)*OFFSET);
>
> and when the 'z' in the if clause (also) became 'z-1'
>
>     c = f (z + (a==b)*2 + (a==b)*OFFSET - (a<=b));
>
> What fun!
> Karl Bochert
>
>
>


May 28, 2002
"Carlos" <carlos8294@msn.com> wrote in message news:acubka$2vqp$1@digitaldaemon.com...
> >
> > I wouldn't mind integrating the various loop structures together
> somehow...
> > a loop is a loop is a loop.  Oftentimes I find myself wanting a for loop
>
> Maybe it'd be nice to have something like VB. If you want to do this (from
> C):
>
> while (cond) {
> ...
> };
>
> you do this (in VB):
>
> do while cond
> ...
> loop

or

while  cond
...
wend

> Or like this:
>
> do until not ( cond )
> ...
> loop
>
> (parenthesis aren't mandatory) Or if you want to do this:
>
> do {
> ...
> } while (cond);
>
> You do this:
>
> do
> ...
> loop while cond
>
> Or
>
> do
> ...
> loop until not (cond)
>
> The do..loop construction in VB is really powerful. You can even write:
>
> do
> ...
> loop
>
> To make an infinite loop. Maybe that (or something like that) could be a solution to have loops integrated under a same instruction.
>
>


May 28, 2002
> >
> > do while cond
> > ...
> > loop
>
> or
>
> while  cond
> ...
> wend
>
yes, but it's strongly not recommended (enough VB. let's return to D)


May 28, 2002
"Andy Walker" <Andy_member@pathlink.com> wrote in message news:acu44e$2fs5$1@digitaldaemon.com...

> My apologies.  I was browsing the code in DedicateD and assumed it was
your.

You've probably seen the SDL samples. No, these aren't mine, I've just translated them to D, and I didn't perform any "beautification".


May 28, 2002
Hi,


"Sean L. Palmer" <seanpalmer@earthlink.net> wrote in message news:acu1qb$26f6$1@digitaldaemon.com...
> You could almost get rid of if entirely by the use of ?: and creative multiplication with 0.

Actually, you can. But the concept of statements makes it hard. In a functional language I designed many years ago, the first couple of years it had no "if"; only "?:". It worked fine because loop constructs and such was operators too, not statements. But, I must admit, the introduction of "if" made the code clearer :-)

Regards,
Martin M. Pedersen



May 28, 2002
"Sean L. Palmer" <seanpalmer@earthlink.net> wrote in message news:acu1qb$26f6$1@digitaldaemon.com...
> You could almost get rid of if entirely by the use of ?: and creative multiplication with 0.  The hardware doesn't have if, it has test-and-branch.  Conditional goto.  Modern processors don't do if statements so well anyway, they interfere with deep pipelining.  Maybe a
new
> kind of conditional construct would be handy?

Don't confuse the higher level language representation from the actual code generated.  A good compiler will match the two.  Anyway, many modern CPUs have a conditional move instruction that would eliminate the branches in this case.

--
 - Stephen Fuld
   e-mail address disguised to prevent spam



>
> Sean
>
> "Martin M. Pedersen" <mmp@www.moeller-pedersen.dk> wrote in message news:acthvu$5b9$1@digitaldaemon.com...
> > "Pavel Minayev" <evilone@omen.ru> wrote in message news:actg00$3eo$1@digitaldaemon.com...
> >
> > >     if (a == b)
> > >         c = f(z);
> > >     else
> > >         c = f(z + 1);
> > >
> > > No brackets! =)
> >
> > c = f(z+(a==b));
> >
> > No if! :-)
>
>
>


May 29, 2002
"Martin M. Pedersen" <mmp@www.moeller-pedersen.dk> wrote in message news:acthvu$5b9$1@digitaldaemon.com...
> "Pavel Minayev" <evilone@omen.ru> wrote in message news:actg00$3eo$1@digitaldaemon.com...
>
> >     if (a == b)
> >         c = f(z);
> >     else
> >         c = f(z + 1);
> >
> > No brackets! =)
>
> c = f(z+(a==b));
>
> No if! :-)
>
>



You don't write an if, but the
conditional check is there allright.
Also, you are making your code dependant
on the fact that false==0 and true==1.
A dangerous assumption...
I think this code is less clear at no gain.
Losing the braces is allright, but losing
the if! No!  :)

--
Stijn
OddesE_XYZ@hotmail.com
http://OddesE.cjb.net
_________________________________________________
Remove _XYZ from my address when replying by mail