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 8641463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:31:54+00:00 2026-06-12T11:31:54+00:00

I created a function that returns a function in Elisp: (defun singleton-set (elem) (defun

  • 0

I created a function that returns a function in Elisp:

(defun singleton-set (elem)
  (defun f (n) (= n elem))
  f)

I try to run this in IELM, and it fails:

ELISP> (singleton-set 5)
*** Eval error ***  Symbol's value as variable is void: f
ELISP> ((singleton-set 5) 5)
*** Eval error ***  Invalid function: (singleton-set 5)

Due to What is the difference between Lisp-1 and Lisp-2? i changed the code to

(defun singleton-set (elem)
  (defun f (n) (= n elem))
  #'f)

And invocation to (funcall (singleton-set 5) 5), but now the error is

*** Eval error *** Symbol's value as variable is void: elem

I understand from elisp: capturing variable from inner function that this is due to dynamic binding of Emacs Lisp.

How to make functions returning functions possible in Emacs Lisp? What is the reason this mechanism is different from other languages like Python, Scala or Clojure?

Related questions:

  • elisp functions as parameters and as return value
  • Elisp interactive function name
  • How to Create a Temporary Function in Emacs Lisp
  • In elisp, how do I put a function in a variable?
  • 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-06-12T11:31:56+00:00Added an answer on June 12, 2026 at 11:31 am

    From the NEWS for Emacs 24:

    Lisp changes in Emacs 24.1

    • Code can now use lexical scoping by default instead of dynamic scoping.
      The lexical-binding variable enables lexical scoping for local
      variables. It is typically set via a file-local variable in the first
      line of the file, in which case it applies to all the code in that
      file.

    So, in Emacs 24:

    (setq lexical-binding t)
    (defun singleton-set (elem) (lambda (n) (= n elem)))
    (mapcar (singleton-set 1) '(0 1 2 3))
        ===> (nil t nil nil)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created an EE plugin with a function that returns an array. e.g. function
I've created a function that returns a nested array based in the values and
I've created a custom function in JMeter that returns a n length string with
I have created a function that will return the string path from my DB.
I have created a function that shows/hides different messages according to a combination of
I'm using C structs in objc and I've created a function that assembles the
I created a generic function that retreives a JSON and parses it: public IList<Object>
I created a PHP function that will automatically turn URLs into links, link Twitter
I created a jQuery function that calls on a PHP server-side file that pulls
I've created a javascript function that will take a hidden span, copy the text

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.