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-18 21:36

>>85
Yes but your macro can't be used as a function pointer, that's the whole point. You can't pass it around as an int(*)(int). You're not calling the return value of the generator as a function; you're calling some other macro, passing in the return value of the generator.

This is why you can almost accomplish this in C++ by creating an object containing the closure values and overriding operator(). You can't store it in a regular function pointer, but you can still call it as a regular function.

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