Objectmix
Tags Register Mark Forums Read

higher-order function : lisp

This is a discussion on higher-order function within the lisp forums in Programming Languages category; Hi everyone, I'm still a Lisp novice. I'm reading by myself the book SICP. I've practiced quite a few exercies in the book and this is my code for the exercise 1.29 about Simpson's Rule: (define (simpson f a b n) (define (yk k) (cond ((even? k) (* 2 (f (+ a (* k (/ (- b a) n)))))) (else (* 4 (f (+ a (* k (/ (- b a) n)))))))) (define (incr a) (+ a 1)) (* (/ (/ (- b a) n) 3) (+ (sum yk 1 incr n) (yk 0)))) The problem is, though I checked ...


Object Mix > Programming Languages > lisp > higher-order function

Reply

 

LinkBack Thread Tools
  #1  
Old 11-03-2007, 05:33 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default higher-order function

Hi everyone,

I'm still a Lisp novice. I'm reading by myself the book SICP. I've
practiced quite a few exercies in the book and this is my code for the
exercise 1.29 about Simpson's Rule:

(define (simpson f a b n)
(define (yk k)
(cond ((even? k) (* 2 (f (+ a (* k (/ (- b a) n))))))
(else (* 4 (f (+ a (* k (/ (- b a) n))))))))
(define (incr a)
(+ a 1))
(* (/ (/ (- b a) n) 3)
(+ (sum yk 1 incr n)
(yk 0))))

The problem is, though I checked on some numbers and the program seems
to work fine, I suspect there may be something wrong. How should I
proceed to check this program? Moreover in any similar situation how
should I test my program?

Thank you.

Mark.

  #2  
Old 11-03-2007, 05:41 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: higher-order function

I should also say that the procedure *sum* is defined in the book by
the authors with the form:

(sum term a next b)

....

and it keeps summing (term a) until a >= b (a is brought to its next
by (next a)).

Thanks.

Mark.

  #3  
Old 11-03-2007, 07:13 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: higher-order function

On Nov 3, 3:33 pm, mark <case.learn...@gmail.com> wrote:
> Hi everyone,
>
> I'm still a Lisp novice. I'm reading by myself the book SICP. I've
> practiced quite a few exercies in the book and this is my code for the
> exercise 1.29 about Simpson's Rule:
>
> (define (simpson f a b n)
> (define (yk k)
> (cond ((even? k) (* 2 (f (+ a (* k (/ (- b a) n))))))
> (else (* 4 (f (+ a (* k (/ (- b a) n))))))))
> (define (incr a)
> (+ a 1))
> (* (/ (/ (- b a) n) 3)
> (+ (sum yk 1 incr n)
> (yk 0))))
>
> The problem is, though I checked on some numbers and the program seems
> to work fine, I suspect there may be something wrong. How should I
> proceed to check this program? Moreover in any similar situation how
> should I test my program?
>
> Thank you.
>
> Mark.


This is a group about common lisp , post your questions to
http://groups.google.com/group/comp....topics?lnk=rgh

Slobodan

  #4  
Old 11-03-2007, 07:35 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: higher-order function

On 4 Nov., 01:13, Slobodan Blazeski <slobodan.blaze...@gmail.com>
wrote:
> On Nov 3, 3:33 pm, mark <case.learn...@gmail.com> wrote:
>
>
>
> > Hi everyone,

>
> > I'm still a Lisp novice. I'm reading by myself the book SICP. I've
> > practiced quite a few exercies in the book and this is my code for the
> > exercise 1.29 about Simpson's Rule:

>
> > (define (simpson f a b n)
> > (define (yk k)
> > (cond ((even? k) (* 2 (f (+ a (* k (/ (- b a) n))))))
> > (else (* 4 (f (+ a (* k (/ (- b a) n))))))))
> > (define (incr a)
> > (+ a 1))
> > (* (/ (/ (- b a) n) 3)
> > (+ (sum yk 1 incr n)
> > (yk 0))))

>
> > The problem is, though I checked on some numbers and the program seems
> > to work fine, I suspect there may be something wrong. How should I
> > proceed to check this program? Moreover in any similar situation how
> > should I test my program?

>
> > Thank you.

>
> > Mark.

>
> This is a group about common lisp ,

...
>
> Slobodan


Almost. It is correct to point out that Scheme-related questions are
best asked on comp.lang.scheme .

comp.lang.lisp is not only about Common Lisp. It is also for general
Lisp discussion. Other dialects of
can also be discussed here, though specific questions should better be
asked on specialized
forums, mailing lists, etc. Some Lisp dialects have their own
newsgroup (Logo, Scheme, Emacs Lisp, ...).
Some don't (ISLisp, ...).

Example: if there is a nice success story of Lisp usage (any Lisp
dialect), comp.lang.lisp is
a fine place to post that story.

Another example: if there is a new book, article, website, ... with
Lisp-related content (again
any Lisp dialect), comp.lang.lisp is a fine place to announce that.

Hint: you may also write Common Lisp answers to Scheme questions. ;-)



Reply

Thread Tools


Similar Threads

Thread Thread Starter Forum Replies Last Post
higher-order-function library? usenet lisp 4 08-08-2007 02:00 AM
Higher Order Instructions usenet DOTNET 8 04-15-2007 04:13 PM
HOM: Higher Order Messaging usenet Object 3 11-07-2006 05:39 PM
higher order function usenet ml 2 08-31-2006 02:59 PM
Higher order curves usenet Java-Games 12 05-15-2005 10:34 PM


All times are GMT -5. The time now is 08:56 AM.

Managed by Infnx Pvt Ltd.