Are lambda expressions / delegates in C # "pure", or can they be?

I recently asked about functional programs that have no side effects, and found out what it means to make parallelized tasks trivial. In particular, these “pure” functions make this trivial because they have no side effects.

I also recently studied LINQ and lambda expressions, as I have come across examples many times in StackOverflow involving an enumeration. This made me wonder if splitting an enumeration or loop can now be "easier" in C #.

Are lambda expressions "clean" enough to remove trivial parallelization? Maybe it depends on what you do with this expression, but can they be clean enough? Is it possible something like this is theoretically possible / trivial in C # ?:

  • Break the cycle into pieces
  • Run the stream to scroll through each fragment
  • Run a function that does something with a value from the current loop position of each thread

For example, let's say I had a lot of objects in the game loop (since I was developing the game and thought about the possibility of several threads) and had to do something with each of them in each frame, pull it trivially? If you look at IEnumerable, it seems to be tracking the current position, so I'm not sure I can use regular general collections to enumerate the enumeration into “pieces”.

. , , . .NET , ​​ .. , , / , .

+5
5

, , , "", . . , , "Math.Sin" . 12 , (12), . GetCurrentTime() , ; , , , .

, ; .

-, , , , . , . , , ; memoization, memoization ( !), , , .

- " ", . , " , ", .

, #, , open-research-problem; no promises, .

+17

. FrameWork .AsParallel LINQ (PLINQ).

, , / .

+13

, . .

: , . .

var i = 0;
Func<bool> del = () => {
  if ( i == 42 ) { return true; }
  else ( i++ ) { return false; }
};

, .

Func<bool> del = () => true;
+3

As for the part of the cycle, you can also use Parallel.For, and Parallel.ForEachfor example, about the objects in the game. It is also part of .net 4, but you can get it as a download.

+3
source

It reads 13 parts that discuss the new support for Parallelism in .NET 4.0 here . It includes a discussion of LINQ and PLINQ, as well as part 7. This is an excellent read, so check it out

+2
source

All Articles