Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add apply-partially defun

  • Loading branch information...
commit 266849caaa473d56ac737ec6dffc260eb41eee72 1 parent 0b06b86
Chris Wanstrath authored August 18, 2011

Showing 1 changed file with 14 additions and 0 deletions. Show diff stats Hide diff stats

  1. 14  coffee-mode.el
14  coffee-mode.el
@@ -144,6 +144,20 @@ to the error, of course."
144 144
   "Keymap for CoffeeScript major mode.")
145 145
 
146 146
 ;;
  147
+;; Compat
  148
+;;
  149
+
  150
+(unless (fboundp 'apply-partially)
  151
+  (defun apply-partially (fun &rest args)
  152
+    "Return a function that is a partial application of FUN to ARGS.
  153
+ARGS is a list of the first N arguments to pass to FUN.
  154
+The result is a new function which does the same as FUN, except that
  155
+the first N arguments are fixed at the values with which this function
  156
+was called."
  157
+    (lexical-let ((fun fun) (args1 args))
  158
+      (lambda (&rest args2) (apply fun (append args1 args2))))))
  159
+
  160
+;;
147 161
 ;; Macros
148 162
 ;;
149 163
 

3 notes on commit 266849c

Daniel Gregoire

Maybe I'm missing something, but elisp already has apply-partially, and is already being used on line 229 inside coffee-compile-region. From the looks of it, this does the same thing.

Is this an Emacs version issue, that earlier versions don't have this fn?

Chris Wanstrath
Owner

It's possible. coffee-compile-region fails for me complaining of no apply-partially defined without this change.

Daniel Gregoire

Gotcha, must be a version thing. I'm using a 24 build for Windows.

As a reference, here's the code for the implemention of apply-partially in Emacs 24:

(defun apply-partially (fun &rest args)
  "Return a function that is a partial application of FUN to ARGS.
ARGS is a list of the first N arguments to pass to FUN.
The result is a new function which does the same as FUN, except that
the first N arguments are fixed at the values with which this function
was called."
  `(closure (t) (&rest args)
            (apply ',fun ,@(mapcar (lambda (arg) `',arg) args) args)))
Please sign in to comment.
Something went wrong with that request. Please try again.