POV-Ray : Newsgroups : povray.off-topic : Standard libraries : Re: Standard libraries Server Time
6 Sep 2024 11:17:16 EDT (-0400)
  Re: Standard libraries  
From: Invisible
Date: 6 Mar 2009 04:08:32
Message: <49b0e810$1@news.povray.org>
Warp wrote:

>   For example the current standard library has a for_each() utility
> function which in theory makes it easier to loop through an iterator
> range and apply some function to each element. However, in practice
> doing this is so cumbersome that few people prefer that over the more
> traditional for loop. The reason is that there's no way in the current
> C++ to embed the function into the for_each() call. Instead, you have
> to write the function separately and give the name to for_each(). Great
> if you already have such a function, but more trouble than it's worth
> if you don't, which means you have to write the function.

Indeed.

Haskell doesn't do anything that's "impossible" with other languages. 
You can do "functional programming" in any programming language that has 
a certain minimal set of features. It's just that in other languages, 
it's so much trouble to write your code in this way that no sane person 
would bother. (Quite apart from the compiler not being specifically 
optimised for it.)

>   Also even if you go through the trouble of writing the function, it
> still has its limits. Most prominently, it's not a closure, which means
> that the function has no access to the variables in the scope where the
> for_each() is executed. This reduces the usability of for_each() even
> further, compared to the traditional for loop (where there rather
> obviously *is* access to all the variables in scope).
> 
>   The C++0x (well, C++1x, really) standard will most probably introduce
> lambda functions and closures, which addresses all these problems, and
> more. You will be able to write your function directly as a parameter
> to for_each() (or whichever generic function you want to use) as a
> lamdba function, and this lambda function can (optionally) have access
> to all the variables in scope.

Mmm, interesting...


Post a reply to this message

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