POV-Ray : Newsgroups : povray.off-topic : An explanation of what next_permutation does : Re: An explanation of what next_permutation does Server Time
4 Sep 2024 17:24:42 EDT (-0400)
  Re: An explanation of what next_permutation does  
From: Darren New
Date: 3 Dec 2009 12:34:20
Message: <4b17f69c$1@news.povray.org>
Invisible wrote:
> "while (!(*i < *--j)) {}"

C has always advocated piling up a bunch of side effects inside 
conditionals.   Even to the point where Google's go has completely useless 
syntax for doing so.

In go, you can write
   if x := y + 1; x > 5 { ... }

Which is always exactly precisely the same as
   x := y + 1;
   if x > 5 { ... }

Since you *always* need braces, and the result of evaluating the assignment 
isn't ever used as the conditional, it's just a way of embedding 
side-effects into a part of a statement that should be side-effect free, 
apparently because the people designing go are so used to C's actually 
*useful* side effects that they missed the result.

The above line could also be
   do { j -= 1; } while (*j <= *i);
(or maybe while *i < *j. I don't care to work it out for sure)

So, yeah, it's opaque C++ code there.


> Um, yeah, "interesting" would be the term I'd use. WTF? o_O

The algorithm is interesting, not the implementation.

-- 
Darren New, San Diego CA, USA (PST)
   Human nature dictates that toothpaste tubes spend
   much longer being almost empty than almost full.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.