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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:24:44+00:00 2026-05-29T13:24:44+00:00

#lang eopl (define (vectorSum V b e) ; b is starting index, and e

  • 0
#lang eopl

(define (vectorSum V b e)    ; b is starting index, and e is ending index
  (cond
    [ (eqv? b e) vector-ref V b]
    [ (> b e)
      (eopl:error 'vectorSum "starting index must be smaller than or equal to the end index")]
    [ else (+ (vector-ref V b) (vectorSum V (+ b 1) e))]))


(define A #(1 1 1 1 1))

When I try this, I am getting the wrong result. What’s the problem here?

> (vectorSum A 0 4)
8
> (vectorSum A 0 1)
2
> (vectorSum A 0 3)
6
> (vectorSum A 1 3)
5
> (vectorSum A 1 2)
3

> (vectorSum A 0 1)
2
> (vectorSum A 1 2)
3

Take (vectorSum A 0 3), when I expanded the recursion, I thought it was supposed to be

+ 1 + VectorSum (1 3)
    + 1 + VectorSum (2, 3)
        + 1 + VectorSum (3, 3)
            + 1   (I hit the first case, there is no more recursion)
= 4

Instead, I get 6. Why?

Thanks.


Look at 0,1 and 1,2 the answers aren’t equal.

  • 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-05-29T13:24:45+00:00Added an answer on May 29, 2026 at 1:24 pm

    Your answer should look like this:

    (define (vectorSum V b e)
      (cond ((eqv? b e)
             (vector-ref V b))
            ((> b e)
             (eopl:error 'partialVectorSum "starting index must be smaller than or equal to the end index"))
            (else (+ (vector-ref V b) (vectorSum V (+ b 1) e)))))
    

    It was a simple mistake – you forgot a couple of parenthesis in this line:

    [ (eqv? b e) vector-ref V b]
    

    It should have been:

    [ (eqv? b e) (vector-ref V b) ]
    

    Without those parenthesis, you’re not actually calling the vector-ref procedure, instead you’re listing some symbols and returning the final one, b in this case. Remember to always surround a procedure call and its arguments between parenthesis, just as you did in the else part.

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

Sidebar

Related Questions

What's the difference between java.lang.ref.WeakReference and java.lang.ref.SoftReference ?
I've been hitting a java.lang.OutOfMemoryError: PermGen error when compiling a project with ant under
In what situations should one catch java.lang.Error on an application?
import java.lang.ref.SoftReference; import java.util.HashMap; import android.graphics.drawable.Drawable; import android.os.Handler; import android.os.Message; public class AsyncImageLoader {
I get a java.lang.NoClassDefFoundError: com/hp/hpl/jena/shared/BadURIException when running a very simple servlet. The error points
I always get java.lang.OutOfMemoryError: Java heap space error when I try to run any
I get a Java.Lang.NoClassDefFoundError error when creating an Intent of a custom class (an
java.lang.IllegalArgumentException: column 'data3' does not exist whats with data3 column?? LogCat 03-24 07:05:36.091: ERROR/AndroidRuntime(2540):
Demo code: import java.lang.ref.PhantomReference; import java.lang.ref.ReferenceQueue; public class Main { public static void main(String[]
Getting this error: java.lang.RuntimeException: An error occured while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:200) at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)

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.