‹ BackHN Continuity

Thread

C++ Insights – See your source code with the eyes of a Compiler

172 points · 36 comments · rramadass

  1. StilesCrisis · · focus · HN ↗
    I wish the readme example showed a lambda capture. Now that's where compiler magic REALLY shows up.
    1. WalterBright · · focus · HN ↗
      Lambdas in D are just nested functions:

          int foo(int i) {
              int add(int x) { return i + x; } // nested function
              return add(3);
          }
      
          int bar(int i {
              alias lambda = (x) => x + i;  // lambda
              return lambda(3);
          }
          }
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.