Permalink
Browse files

add apply-partially defun

  • Loading branch information...
1 parent 0b06b86 commit 266849caaa473d56ac737ec6dffc260eb41eee72 @defunkt committed Aug 19, 2011
Showing with 14 additions and 0 deletions.
  1. +14 −0 coffee-mode.el
View
@@ -144,6 +144,20 @@ to the error, of course."
"Keymap for CoffeeScript major mode.")
;;
+;; Compat
+;;
+
+(unless (fboundp 'apply-partially)
+ (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."
+ (lexical-let ((fun fun) (args1 args))
+ (lambda (&rest args2) (apply fun (append args1 args2))))))
+
+;;
;; Macros
;;

3 comments on commit 266849c

Contributor

semperos replied Aug 19, 2011

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?

Owner

defunkt replied Aug 19, 2011

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

Contributor

semperos replied Aug 19, 2011

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.