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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:42:23+00:00 2026-06-03T04:42:23+00:00

In Peter Norvig’s epic tome Paradigms of Artifical Intelligence Programming in Chapter 7 –

  • 0

In Peter Norvig’s epic tome Paradigms of Artifical Intelligence Programming in Chapter 7 – he describes a function interp which is effectively a simple eval function used when interpreting a bare-bones Scheme in a REPL.

(defun interp (x &optional env)
  "Interpret (evaluate) the expression x in the environment env."
  (cond
    ((symbolp x) (get-var x env))
    ((atom x) x)
    ((case (first x)
       (QUOTE  (second x))
       (BEGIN  (last1 (mapcar #'(lambda (y) (interp y env))
                              (rest x))))
       (SET!   (set-var! (second x) (interp (third x) env) env))
       (IF     (if (interp (second x) env)
                   (interp (third x) env)
                   (interp (fourth x) env)))
       (LAMBDA (let ((parms (second x))
                     (code (maybe-add 'begin (rest2 x))))
                 #'(lambda (&rest args)
                     (interp code (extend-env parms args env)))))
       (t      ;; a procedure application
               (apply (interp (first x) env)
                      (mapcar #'(lambda (v) (interp v env))
                              (rest x))))))))

Interestingly enough – the opening Chapter of Christian Queinnec’s Lisp In Small Pieces has a very similar function, he calls it eval.

;;; This is a naive evaluator for Scheme written in naive Scheme.

(define (evaluate e env)
  (if (atom? e) 
      (cond ((symbol? e) (lookup e env))
            ((or (number? e) (string? e) (char? e)
                 (boolean? e) (vector? e) )
             e )
            (else (wrong "Cannot evaluate" e)) )
      (case (car e)
        ((quote)  (cadr e))
        ((if)     (if (evaluate (cadr e) env)
                      (evaluate (caddr e) env)
                      (evaluate (cadddr e) env) ))
        ((begin)  (eprogn (cdr e) env))
        ((set!)   (update! (cadr e) env (evaluate (caddr e) env)))
        ((lambda) (make-function (cadr e) (cddr e) env))
        (else     (invoke (evaluate (car e) env)
                          (evlis (cdr e) env) )) ) ) )

My question is – where is the Clojure source is the equivalent eval/interp function? I assume it is in the reader code somewhere.

  • 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-03T04:42:24+00:00Added an answer on June 3, 2026 at 4:42 am

    You mean, what’s Clojure’s eval procedure? That’d be clojure.core/eval. This link from the documentation shows how evaluation occurs:

    • Interactively, in the REPL
    • On a sequence of forms read from a stream, via load or load-file
    • Programmatically, via eval

    If you’re interested in the actual source code, take a look at Clojure’s core.clj file. In particular, the code for eval looks like this:

    (defn eval
      "Evaluates the form data structure (not text!) and returns the result."
      [form] (. clojure.lang.Compiler (eval form)))
    

    In turn, the eval method from the Compiler class (referenced in the above snippet, and residing in the Compiler.java file) looks like this:

    public static Object eval(Object form) throws Exception{
        boolean createdLoader = false;
        if(true)//!LOADER.isBound())
            {
            Var.pushThreadBindings(RT.map(LOADER, RT.makeClassLoader()));
            createdLoader = true;
            }
        try
            {
            Integer line = (Integer) LINE.deref();
            if(RT.meta(form) != null && RT.meta(form).containsKey(RT.LINE_KEY))
                line = (Integer) RT.meta(form).valAt(RT.LINE_KEY);
            Var.pushThreadBindings(RT.map(LINE, line));
            try
                {
                form = macroexpand(form);
                if(form instanceof IPersistentCollection && Util.equals(RT.first(form), DO))
                    {
                    ISeq s = RT.next(form);
                    for(; RT.next(s) != null; s = RT.next(s))
                        eval(RT.first(s));
                    return eval(RT.first(s));
                    }
                else if(form instanceof IPersistentCollection
                        && !(RT.first(form) instanceof Symbol
                             && ((Symbol) RT.first(form)).name.startsWith("def")))
                    {
                    FnExpr fexpr = (FnExpr) analyze(C.EXPRESSION, RT.list(FN, PersistentVector.EMPTY, form), "eval");
                    IFn fn = (IFn) fexpr.eval();
                    return fn.invoke();
                    }
                else
                    {
                    Expr expr = analyze(C.EVAL, form);
                    return expr.eval();
                    }
                }
            finally
                {
                Var.popThreadBindings();
                }
            }
        catch(Throwable e)
            {
            if(!(e instanceof CompilerException))
                throw new CompilerException((String) SOURCE.deref(), (Integer) LINE.deref(), e);
            else
                throw (CompilerException) e;
            }
        finally
            {
            if(createdLoader)
                Var.popThreadBindings();
            }
    }
    

    I guess that’s not quite what you expected it to be, but given the fact that Clojure runs on top of the JVM, it makes sense that the evaluation part occurs as a Java program and not as a Lisp program – as is the case in the code referenced in the question.

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

Sidebar

Related Questions

I'm reading over Peter Norvig's Paradigms of Artificial Intelligence Programming, and I've come across
Peter Norvig mentions in Paradigms of Artificial Intelligence Programming , on page 50 ,
In the article Teach Yourself Programming in Ten Years Peter Norvig (Director of Research,
I am learning Expert C Programming by Peter Van Der Linden. In chapter A.6,
I saw Michael Sparks's very interesting dissection of Peter Norvig's Spell Checker at the
I have a textfield which takes in full name example: michael peter johnson in
Taking Peter Norvig's advice , I am pondering on the question: How much time
I was looking at an article on Peter Norvig's website, where he's trying to
I was looking through Expert C Programming by Peter Van Der Linden recently and
Peter Norvig has an essay describing a program to solve sudoku puzzles , even

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.