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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:52:55+00:00 2026-05-28T01:52:55+00:00

I’ve been doing some homework, wrote some code and can’t actually find the reason

  • 0

I’ve been doing some homework, wrote some code and can’t actually find the reason why it doesn’t work. The main idea of this part of the work is to make a stream that will give me elements of Taylor series of cosine function for a given X (angle i guess). anyways here is my code, I’d be happy if some one could point me to the reasons it doesn’t work 🙂

(define (force exp) exp)
(define (s-car s) (car s))
(define (s-cdr s) (force (cdr s)))

; returns n elements of stream s as a list
(define (stream->list s n)
  (if (= n 0) 
      '()
      (cons (s-car s) (stream->list (s-cdr s) (- n 1)))))

; returns the n-th element of stream s
(define stream-ref (lambda (s n)
                     (if (= n 1)
                         (s-car s)
                         (stream-ref (s-cdr s) (- n 1)))))

; well, the name kinda gives it away :) make factorial n!
(define (factorial x)
        (cond ((= x 0) 1)
              ((= x 1) 1)
              (else (* x (factorial (- x 1))))))

; this function is actually the equation for the 
; n-th element of Taylor series of cosine
(define (tylorElementCosine x)
  (lambda (n)
     (* (/ (expt -1 n) (factorial (* 2 n))) (expt x (* 2 n)))))

; here i try to make a stream of those Taylor series elements of cosine
(define (cosineStream x)
  (define (iter n)
    (cons ((tylorElementCosine x) n)
          (lambda() ((tylorElementCosine x) (+ n 1)))))
  (iter 0))

; this definition should bind cosine
; to the stream of taylor series for cosine 10
(define cosine (cosineStream 10)) 
(stream->list cosine 10) 
; this should printi on screen the list of first 10 elements of the series

However, this doesn’t work, and I don’t know why.

I’m using Dr.Scheme 4.2.5 with the language set to “Essentials of Programming Languages 3rd ed”.

  • 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-28T01:52:56+00:00Added an answer on May 28, 2026 at 1:52 am

    Since I was feeling nice (and nostalgic about scheme) I actually waded through your code to finde the mistakes. From what I can see there are 2 problems which keeps the code from running as it should:

    If I understand your code correctly (force exp) should evaluate exp, however you directly return it (unevaluated). So it probably should be defined as (define (force exp) (exp))

    The second problem is in your lambda: (lambda() ((tylorElementCosine x) (+ n 1)) ) will evaluate to the next element of the taylor series, while it should evaluate to a stream. You probably want something like this: (lambda() (iter (+ n 1)) )

    I haven’t checked if the output is correct, but with those modifications it does at least run. So if there are any more problems with the code the should be in the formula used.

    However I’d suggest that next time you want help with your homework you at least tell us where exactly the problem manifests and what you tried already (the community does frown on “here is some code, please fix it for me” kind of questions).

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
For some reason, after submitting a string like this Jack’s Spindle from a text
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string

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.