문제

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

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top