Scheme

时间:2019-01-09 19:28:06

标签: scheme complex-numbers

(define (complex-num x y)
      (cons x y))
(define (real x) 
      (car x)) 
(define (imag x) 
       (cdr x)) 

对吗?或者,也许您可​​以建议一种更好的方法。

1 个答案:

答案 0 :(得分:1)

Yes, that's a correct way to represent complex numbers in Scheme. It's also possible to alias the procedures, because you're calling them directly:

(define complex-num cons)
(define real car)
(define imag cdr)

... But it's a matter of taste, and anyway your solution is easier to understand.