Scheme and let syntax

(define (Integral fab N) ;define h as a constant (let((h (/ (- ba) N)))) (define (Term n) (* (/ h 3) (+ (* 2 (f (+ a (* 2 (* nh))))) (* 4 (f (+ a (* 2 (* (- n 1) h))))) ) )) (+ (* (/ h 3) (+ (fa) (fb))) (sum Term a next (/ N 2.0)))) 

This code throws an error r5rs: body: there is no expression in the body in: (r5rs: body) Could you help?

+4
source share
1 answer

You removed the brackets after let. Once you have defined the constant, let the code that uses the constant be inside the let scope. Therefore, your mistake is the lack of an expression body.

Here is the corrected code:

 (define (Integral fab N) ; define h as a constant (let ((h (/ (- ba) N))) (define (Term n) (* (/ h 3) (+ (* 2 (f (+ a (* 2 (* nh))))) (* 4 (f (+ a (* 2 (* (- n 1) h)))))))) (+ (* (/ h 3) (+ (fa) (fb))) (sum Term a next (/ N 2.0))))) 

By the way, you still need to define the sum function.

+6
source

Source: https://habr.com/ru/post/1303079/


All Articles