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

  • SEARCH
  • Home
  • 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 8167013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:04:20+00:00 2026-06-06T20:04:20+00:00

Functions with closures seem to break when used with eval . (eval {:fn (let

  • 0

Functions with closures seem to break when used with eval.

(eval {:fn (let [x "foo"] (fn [] "x"))})
;=> {:fn #<user$eval14716$fn__14717 user$eval14716$fn__14717@1ddd735>}

(eval {:fn (let [x "foo"] (fn [] x))})
;=> IllegalArgumentException No matching ctor found for class user$eval14740$fn__14741 
;   clojure.lang.Reflector.invokeConstructor (Reflector.java:166)

I don’t really know enough about Clojure (or closure) to know if this is a bug or something which intentionally isn’t allowed – can anyone shed some light on this?

Edit: Just to be clear, I’m talking specifically about the way eval handles function objects. AFAIK eval is actually designed to work with java objects, including functions; the example given on the clojure website – (eval (list + 1 2 3)) – passes a function object into eval.

  • 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-06T20:04:21+00:00Added an answer on June 6, 2026 at 8:04 pm

    Cloure’s eval does not perfectly support function objects. It’s not necessarily even closures that cause the problem.

    For example, this did not work in Clojure 1.0.0:

    (eval {:fn (fn [x] x)})
    

    But this did:

    (eval (fn [x] x))
    

    The first example got fixed. The following also works:

    (eval (let [x "foo"] (fn [] x)))
    

    But the following still does not work:

    (eval {:fn (let [x "foo"] (fn [] x))})
    

    I can’t pin it down to a single line in the compiler, but it’s something about how literal objects (clojure.lang.Compiler$ObjExpr I think) get handled by eval in different contexts: e.g. at the “top” of an expression versus inside another data structure.

    In general, I think, you cannot rely on being able to eval function objects in Clojure, regardless of whether or not they are closures. It happens to work for some simple examples, mostly to simplify the explanation of things like (eval (list + 1 2)). Macros should always return literal source code as data structures, not compiled functions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Many functions in c take pointer to constant strings/chars as parameters eg void foo(const
Question: There seem to be many benefits to Closures, but what are the negatives
Would some enlighten on the difference of Inner(Private) functions and Closures, as they appear
With C++11, we get lambdas, and the possibility to create functions/functors/closures on-the-fly where we
I am a C# developer and used to the way closures work in C#.
In JavaScript nested functions are very useful: closures, private methods and what have you..
Why are inline closures so rarely used in Actionscript? They are very powerful and
Lua has a really nice no-parenthesis call syntax that coupled with function closures allow
PHP functions such as 'array_map' take a callback, which can be a simple function
Should functions that act on and object, say to fill it out from xml,

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.