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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:09:35+00:00 2026-05-11T01:09:35+00:00

One long term project I have is working through all the exercises of SICP.

  • 0

One long term project I have is working through all the exercises of SICP. I noticed something a bit odd with the most recent exercise. I am testing a Huffman encoding tree. When I execute the following code in DrScheme I get the expected result:

(a d a b b c a) 

However, if I execute this same code in mzscheme by calling (load ‘2.67.scm’) or by running mzscheme -f 2.67.scm, it reports:

symbols: expected symbols as arguments, given: (leaf D 1)  

My question is: why? Is it because mzscheme and drscheme use different rules for loading program definitions? The program code is below.

;; Define an encoding tree and a sample message ;; Use the decode procedure to decode the message, and give the result.   (define (make-leaf symbol weight)   (list 'leaf symbol weight)) (define (leaf? object)   (eq? (car object) 'leaf)) (define (symbol-leaf x) (cadr x)) (define (weight-leaf x) (caddr x))  (define (make-code-tree left right)   (list left         right         (append (symbols left) (symbols right))         (+ (weight left) (weight right))))  (define (left-branch tree) (car tree)) (define (right-branch tree) (cadr tree))  (define (symbols tree)   (if (leaf? tree)       (list (symbol-leaf tree))       (caddr tree))) (define (weight tree)   (if (leaf? tree)       (weight-leaf tree)       (cadddr tree)))  (define (decode bits tree)   (define (decode-1 bits current-branch)     (if (null? bits)         '()         (let ((next-branch                (choose-branch (car bits) current-branch)))           (if (leaf? next-branch)               (cons (symbol-leaf next-branch)                     (decode-1 (cdr bits) tree))               (decode-1 (cdr bits) next-branch)))))   (decode-1 bits tree)) (define (choose-branch bit branch)   (cond ((= bit 0) (left-branch branch))         ((= bit 1) (right-branch branch))         (else (error 'bad bit -- CHOOSE-BRANCH' bit))))  (define (test s-exp)   (display s-exp)   (newline))  (define sample-tree   (make-code-tree (make-leaf 'A 4)                   (make-code-tree                    (make-leaf 'B 2)                    (make-code-tree (make-leaf 'D 1)                                    (make-leaf 'C 1)))))  (define sample-message '(0 1 1 0 0 1 0 1 0 1 1 1 0))  (test (decode sample-message sample-tree)) 
  • 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. 2026-05-11T01:09:35+00:00Added an answer on May 11, 2026 at 1:09 am

    By default, MzScheme starts in a mode where there is an existing definition for symbols, and it inlines functions that it knows about — so when it compiles your make-code-tree definition, it uses the binding it knows about. When it later compiles your symbols, it doesn’t have an effect on the previous definition.

    The easiest way to deal with this is to make your code into a module, by prefixing it with a #lang scheme.

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

Sidebar

Ask A Question

Stats

  • Questions 62k
  • Answers 62k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The two previous answers got it right - I don't… May 11, 2026 at 10:15 am
  • added an answer I haven't tried it, but image_bundle appears to be what… May 11, 2026 at 10:15 am
  • added an answer Another advantage to using an explicit type parameter would be… May 11, 2026 at 10:15 am

Related Questions

One long term project I have is working through all the exercises of SICP.
Suppose I have one long long int and want to take its bits and
I've got one long GridView control on ma website. It allows row selection. The
In my app I have 2 divs, one with a long list of products
One of the web pages on our site is extremely long. Although the page
Estimating how long any given task will take seems to be one of the
I have long since forgotten the password for the root user on one of
Long winded title, short question: If one wants to develop for Windows but not
I know this one is going to be a long-shot, but I thought I'd
Our build server is taking too long to build one of our C++ projects.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.