Question

I'm trying to convert from polar to rectangular, I write this code

(define (polar_to_rectangular h r)
  (cons
     (* (sin (DegreesToRadians h)) r) 
     (* (cos (DegreesToRadians h)) r)
  )
 )

but I have this error cons: second argument must be a list, but received #i4.999999999999999 and #i8.660254037844387

the result is correct but still got the error any help please!!

Était-ce utile?

La solution

I'm guessing that you're using DrRacket. The error reported happens because the teaching language in use doesn't allow to pass a non-list as the second parameter of cons. Use a list instead:

(define (polar_to_rectangular h r)
  (list
     (* (sin (DegreesToRadians h)) r) 
     (* (cos (DegreesToRadians h)) r)))

Or if you definitely have to use cons, then in the bottom-left corner of the window select "Determine language from source" and write this line at the beginning of the file:

#lang racket
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top