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!!

Was it helpful?

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top