Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6728293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:09:11+00:00 2026-05-26T10:09:11+00:00

The Emacs code for apply-partially is this: (defun apply-partially (fun &rest args) Return a

  • 0

The Emacs code for apply-partially is this:

(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)))

It returns a list that looks a lot like a lambda expression, except that lambda is replaced by closure (t). For example, (apply-partially 'cons 1) returns this:

(closure (t) (&rest args) (apply (quote cons) (quote 1) args))

which, as far as I can tell, looks and works exactly like this:

(lambda (&rest args) (apply (quote cons) (quote 1) args))

except that the “closure” expression does not have the “self-quoting” property of a lambda, so when I try to evaluate it, Emacs informs me that closure has no function definition: Lisp error: (void-function closure).

I can’t find any references in the Elisp manual to using the symbol closure in this way. It seems like some kind of internal Emacs magic. The closure expression is clearly not being evaluated according to the normal rules (since doing that manually gives an error).

So what’s going on here? Do I need to grep the C code for references to “closure” to find out?

EDIT: It appears that in Emacs 23 and below, apply-partially simply uses the lexical-let from the cl package to make a closure. The definition above is from version “24.0.90.1”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:09:11+00:00Added an answer on May 26, 2026 at 10:09 am

    I found the answer in eval.c, in the funcall_lambda function:

      if (EQ (XCAR (fun), Qclosure))
    {
      fun = XCDR (fun); /* Drop `closure'.  */
      lexenv = XCAR (fun);
      CHECK_LIST_CONS (fun, fun);
    }
      else
    lexenv = Qnil;
    

    closure (t) appears to be the lexical equivalent of lambda. The second element, (t), gets assigned to lexenv, so I guess this element is for closing over lexical values defined outside of the function itself or something.

    I suspect that the lack of self-quoting may be an oversight, which can be remedied as follows:

    (defmacro make-self-quoting (name)
      "Make NAME into a self-quoting function like `lambda'."
      `(defmacro ,name (&rest cdr)
         (list 'function (cons ',name cdr))))
    (make-self-quoting closure)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What Visual Studio settings and .emacs macros improve the likelihood that code written on
I configured my Emacs for code completion and other help using this link (from
I have a emacs mode hook code (defun php-mode-hook () (setq tab-width 4 c-basic-offset
I've found several code completion elisp packages for emacs that do code completion, but
Update: Note that this thread does not applyt o recent versions of Emacs (24+).
I'm using GNU Emacs 22.2.1 and cperl 5.23. I have perl code like this:
I'm trying to code up an Emacs script that has to manipulate the clipboard
I wondering if there is a set of Emacs Lisp code that implements some
I'm trying to figure out how to use Emacs Code Browser (ECB) and one
How can you import a new chunk of code (an Emacs lisp library) into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.