Headers Including Each Other in C++

I’m a C++ newbie, but I wasn’t able to find the answer to this (most likely trivial) question online. I am having some trouble compiling some code where two classes include each other. To begin, should my #include statements go inside or outside of my macros? In practice, this hasn’t seemed to matter. However, in … Read more

Does CUDA support recursion?

Does CUDA support recursion? Answer It does on NVIDIA hardware supporting compute capability 2.0 and CUDA 3.1: New language features added to CUDA C / C++ include: Support for function pointers and recursion make it easier to port many existing algorithms to Fermi GPUs http://developer.nvidia.com/object/cuda_3_1_downloads.html Function pointers: http://developer.download.nvidia.com/compute/cuda/sdk/website/CUDA_Advanced_Topics.html#FunctionPointers Recursion: I can’t find a code sample … Read more

Can an anonymous method in C# call itself?

I have the following code: class myClass { private delegate string myDelegate(Object bj); protected void method() { myDelegate build = delegate(Object bj) { var letters= string.Empty; if (someCondition) return build(some_obj); //This line seems to choke the compiler else string.Empty; }; …… } } Is there another way to set up an anonymous method in C# … Read more

Method to get all files within folder and subfolders that will return a list

I have a method that will iterate through a folder and all of its subfolders and get a list of the file paths. However, I could only figure out how to create it and add the files to a public List, but not how to return the list. Here’s the method: public List<String> files = … Read more

Infinite loop in constructor without for or while

I did a test here, but the output is a loop without ending, I don’t know why. Actually, I am doing another test, but when I wrote this, I don’t understand how the loop occurred. It is output “ABC” repeatedly. #include <map> #include <string> #include <iostream> class test { public: std::map <int, int> _b; test(); … Read more

How do I replace while loops with a functional programming alternative without tail call optimization?

I am experimenting with a more functional style in my JavaScript; therefore, I have replaced for loops with utility functions such as map and reduce. However, I have not found a functional replacement for while loops since tail call optimization is generally not available for JavaScript. (From what I understand ES6 prevents tail calls from … Read more

Defining and calling function in one step

Is there a way in Javascript to define a function and immediately call it, in a way that allows it to be reused? I know you can do one-off anonymous functions: (function(i) { var product = i * i; console.log(product); // Can’t recurse here because there’s no (ECMA standard) way for the // function to … Read more

Why should recursion be preferred over iteration?

Iteration is more performant than recursion, right? Then why do some people opine that recursion is better (more elegant, in their words) than iteration? I really don’t see why some languages like Haskell do not allow iteration and encourage recursion? Isn’t that absurd to encourage something that has bad performance (and that too when more … Read more