YpaHeL1
YpaHeL1

Reputation: 113

Scheme: variable required in this context

I use mit-scheme compiler for learning Scheme.

The program which I write must compute equation roots via Vieta theorem.

(define (roots p q x-begin x-end)
    (let ((x1 0.0) (x2 0.0))
        (set! (x1 x-begin)) ; Error here Variable required in this context: (x1 x-begin)
        (set! (x2 x-begin))

        ; ...  
    )   
)

I guess that error concerned with static scope in Scheme. What i do wrong?

P.S. Sorry for my english.

Upvotes: 0

Views: 100

Answers (1)

Óscar López
Óscar López

Reputation: 235984

I'm not sure how you intend to calculate the roots but I can provide some advise regarding Scheme syntax, this is incorrect:

(set! (x1 x-begin))

It should be:

(set! x1 x-begin)

In general, using set! should be avoided whenever possible: in Scheme we try real hard to write programs that follow the functional-programming paradigm, and that includes not reassigning variables.

Upvotes: 2

Related Questions