質問

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