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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:54:55+00:00 2026-06-08T11:54:55+00:00

Using Clojure 1.2, this code works (defn A [] (fn [a] (+ a 2)))

  • 0

Using Clojure 1.2, this code works

(defn A [] (fn [a] (+ a 2)))
(println ((A) 0))
(println (eval (list (A) 0)))

but the following code fails on the third line

(defn A [b] (fn [a] (+ a b)))
(println ((A 3) 0))
(println (eval (list (A 3) 0)))

Why?

  • 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-08T11:54:56+00:00Added an answer on June 8, 2026 at 11:54 am

    Calling (list (A 3)) returns a function in a list:

    user> (list (A 3) 0)
    (#<user$A$fn__2934 user$A$fn__2934@2f09b4cb> 0)
    

    eval expects to get a symbol in a list and it was getting the function it’s self. if you quote the call to (A 3) then you will get the result you seek

    user> (println (eval (list '(A 3) 0)))
    3
    nil
    

    Part of this code is being evaluated before the call to eval and then eval is evaluating the rest. It is more common to se eval used on quoted forms with perhaps a term or
    to selectively unquoted (~).

    user> (eval '((A 3) 0))
    3
    

    or

    user> (def my-number 3)
    #'user/my-number
    user> (eval `((A ~my-number) 0))
    3
    

    edit: on the question of why it works with zero args and fails with one arg:

    it seems that both forms work if you don’t store them in vars (ie define them with defn)
    and instead manually inline them:

    user> (def A (fn [b] (fn [a] (+ a b))))
    #'user/A
    user> (eval (list (A 3) 0))
    ; Evaluation aborted.
    user> (eval (list (fn [b] (fn [a] (+ a b)) 3) 0))
    3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using clojure and hiccup (with noir) and I have this code: (defn
I'm using Maven in the context of another build-tool (leiningen for Clojure, but this
I typed this into Clojure REPL (using the enclojure Netbeans plugin): user=> hello, world
I installed clojure-mode and slime using the emacs starter kit and I get this
I'm happily using swank-clojure, installed via elpa. But I'd like to do some work
I am trying to solve Project Euler problem in Clojure using recursion. The following
The following piece of Clojure code results in java.lang.StackOverflowError when I call it with
I am attempting to interop to this simple scala code, but am having some
I'm having a problem when using group-by. Here is the code (defn combine-by-coords [values]
I'm using this code to show messages: Common.getHandler().post(new Runnable(){ public void run(){ Toast.makeText(Common.getContext(), 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.