title: Currying a function in emacs lisp
body: <p>I have many handy functions which operate on the current word or region, and due to laziness etc. I've build them out of a template...</p>
  
  <p>For example </p>
  
  <pre><code>(defun lower-camelcase-at-point-or-region ()
    "lowerCamelCaseTheCurrent dashed or snake_case word or any words in text selection."
    (interactive)
    (let (pos1 pos2 meat)
      (if (and transient-mark-mode mark-active)
          (setq pos1 (region-beginning)
                pos2 (region-end))
        (setq pos1 (car (bounds-of-thing-at-point 'symbol))
              pos2 (cdr (bounds-of-thing-at-point 'symbol))))
      (setq meat (s-lower-camel-case (buffer-substring-no-properties pos1 pos2)))
      (delete-region pos1 pos2)
      (insert  meat)    
      )
    )
  </code></pre>
  
  <p>Effectively this is all boiler plate, except for this line...</p>
  
  <pre><code>(setq meat (s-lower-camel-case (buffer-substring-no-properties pos1 pos2)))
  </code></pre>
  
  <p>Where I call <code>s-lower-camel-case</code> on the buffer substring. I want to reuse the at point or region stuff, but without duplicating it everywhere, (because that's stupid, and a headache to maintain.)</p>
  
  <p>So what I really want to know is, can I curry functions in Emacs Lisp?</p>
  
  <p>When I tried this...</p>
  
  <pre><code>(defun do-stuff-on-point-or-region ()
    "Do stuff."
    (interactive)
    (operate-on-point-or-region 's-lower-camel-case)
  )
  </code></pre>
  
  <p>With <code>operate-on-point-or-region</code> defined as...:</p>
  
  <pre><code>(defun operate-on-point-or-region (fn)
    "Pick the substring at point, or region 
     and replace it with the output of fn"
    (let (pos1 pos2 meat)
      (if (and transient-mark-mode mark-active)
          (setq pos1 (region-beginning)
                pos2 (region-end))
        (setq pos1 (car (bounds-of-thing-at-point 'symbol))
              pos2 (cdr (bounds-of-thing-at-point 'symbol))))
      (setq meat (fn (buffer-substring-no-properties pos1 pos2)))
      (delete-region pos1 pos2)
      (insert  meat)    
      )
  )
  </code></pre>
  
  <p>I get : <code>Symbol's function definition is void: fn</code></p>
  
  <p>Am I foolishly assuming currying is possible in Emacs Lisp!? Or am I just doing it wrong?</p>