Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

PROGRAMMING CHALLENGE

Name: Anonymous 2010-07-16 18:57


This one should be difficult enough for you guys,

Write a function foo that takes a number n and returns a function that takes a number i, and returns n incremented by i.


My submission, in Scheme


(define (foo num)
  (lambda (x) (+ x num)))

Name: Anonymous 2010-07-16 19:56

>>12
Wrong. A real EXPERT C89 PROGRAMMER would use the preprocessor.


#define FOO(n) F##n
#define MAKE_FOO(n) int F##n##(int i) { return n + i; }

MAKE_FOO(0)
MAKE_FOO(1)
MAKE_FOO(2)
MAKE_FOO(3)
MAKE_FOO(4)
MAKE_FOO(5)
MAKE_FOO(6)
MAKE_FOO(7)

int main(int argc, char **argv) {
    int (*f)(int) = FOO(2)
    printf("%d\n", f(11));
    return 0;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List