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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:27:25+00:00 2026-06-07T22:27:25+00:00

I struggle to understand a point in the code by Peter Norvig, ‘Even better

  • 0

I struggle to understand a point in the code by Peter Norvig, ‘Even better Python Lisp interpreter’, here.

In eval function, aimed at parsing, he is doing the test isanstance(x,Symbol). Class Symbol is defined before, but it has no method, since it is declared with pass:

 class Symbol(str): pass

These lines build a symbol_table.

def Sym(s, symbol_table={}):
    "Find or create unique Symbol entry for str s in symbol table."
    if s not in symbol_table: symbol_table[s] = Symbol(s)
    return symbol_table[s]

_quote, _if, _set, _define, _lambda, _begin, _definemacro, = map(Sym, 
"quote   if   set!  define   lambda   begin   define-macro".split())

_quasiquote, _unquote, _unquotesplicing = map(Sym,
"quasiquote   unquote   unquote-splicing".split())

I don’t understand why Symbol(s) is working, since no constructor for Symbol class has been defined. Afterwards, eval method checks whether the token is a Symbol the following way:

def eval(x, env=global_env):
     "Evaluate an expression in an environment."
      while True:
          if isa(x, Symbol):       # variable reference
              return env.find(x)[x]
          else: #other stuff

isa(x,Symbol) is a mystery. Here in code, should check whether token is a variable reference (that is x, with x that have been defined before). In my opinion, Symbol(s) here are a decoration for strings, in the initialization list built with

  _quote, _if, _set, _define, _lambda, _begin, _definemacro, = map(Sym, 
     "quote   if   set!  define   lambda   begin   define-macro".split())

Could you please explain based on your knowledge or reading of this code by P. Norvig or experience of Python? Thanks

  • 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-07T22:27:26+00:00Added an answer on June 7, 2026 at 10:27 pm

    Like all other methods, __init__ is inherited. Symbol inherits str‘s __init__.

    Update: Note further that __init__ performs initialisation, not construction, and that initialisation code (with a slightly different effect) can also exist inside the class definition. This means that a valid object can exist without __init__ even needing to be called.

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

Sidebar

Related Questions

I had a bit of a struggle trying to understand why my code was
With C++, I struggle to understand one compilation error. I have this function, with
struggle extracting necessary data from this complex json stored inside php variable. Via php
I struggle on a System.OutOfMemoryException when performing an import process where a lot of
I struggle a little with the understanding of generics and how they can and
I struggle with finding a good medium on communication. In our jobs, it seems
I struggle to use a jquery selector containing brakcets. Basically I parse a JSON
I struggle to uninstall VS 2010. I downloaded and used first trial version for
I'm struggle extracting necessary data from this json stored inside php variable. Not yet
I'm continuing to struggle with the MVVM pattern and, in attempting to create a

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.