title: simple higher order functions in scheme
body: <p>I'm trying to understand how to pass functions as arguments in scheme but I'm having a lot of trouble understanding tutorials.
  Here's what I'm trying to do:</p>
  
  <pre><code>(define (addone n)
  (+ n 1))
  (define (for-n start stop fn)
  (if (&lt; start stop)
      (list)
      (cons (fn start) (for-n (+ start 1) stop fn))))
  </code></pre>
  
  <p>Basically I just want a function that returns the values of fn for start, start+1, ... start+stop in a list.</p>
  
  <p>Expected output of (for-n 1 5 (addone 0)) would thus be (1 2 3 4 5).
  I think I'm really missing some very basic concepts here because I don't seem to even be calling the function in the interpreter correctly and I'm not grasping how to tell scheme to interpret fn as a function rather than just a regular parameter.</p>
  
  <p>I figured it out (though through sheer trial and error) and I'm not sure what I did but at least it works!</p>
  
  <pre><code> (define (function x)
      x)
  (define (for-n start stop fn)
    (if (&gt; start stop)
      (list)
      (cons (fn start) (for-n (+ start 1) stop fn)))))
  </code></pre>