NXXX4
Functional Functions - A Comprehensive Proposal Overviewing Blocks, Nested Functions, and Lambdas for C

Published Proposal,

Previous Revisions:
None
Authors:
Paper Source:
GitHub
Issue Tracking:
GitHub
Project:
ISO/IEC 9899 Programming Languages — C, ISO/IEC JTC1/SC22/WG14
Proposal Category:
Change Request, Feature Request
Target:
C2y/C3a

Abstract

Nested Functions (GCC), Blocks (Clang & Apple-derived compilers), Wide Function Pointers (Borland and existing C library functions), and Lambdas (C++) provide a series of takes on how to, effectively, bundle functions with data in different ways and transport that information to the caller. This proposal goes through the existing practice and enumerations their tradeoffs so as to propose the best possible solution to the problem space at hand.

1. Changelog

2. Introduction and Motivation

Meow. :3

Bark. :3

3. Design

3.1. Nested Function Rehabilitations

int main () {
  int x = 3;
  int zero () {
    // OK, no external variables sued
    return 0;
  }
  int double_it () {
    return x * 2; // constraint violation
  }
  int triple_it () _Capture(x) {
    return x * 3; // OK, x = 3 when called
  }
  int quadruple_it () _Capture(&x) {
    return x * 4; // OK, x = 5 when called
  }
  int quintuple_it () _Capture(=) {
    return x * 5; // OK, x = 3 when called
  }
  int sextuple_it () _Capture(&) {
    return x * 6; // OK, x = 5 when caled
  }
  x = 5;
  return zero() + triple_it() + quadruple_it()
    + quintuple_it() + sextuple_it();
  // return 74;
  // 0 + (3 * 3) + (5 * 4)
  // (3 * 5) + (5 * 6)
}

Upsides:

Downsides: