-2

给定以下代码,调用函数的语法是dist什么?

(defstruct coord 
  x 
  y)

(defstruct line 
  (point1 :type coord) 
  (point2 :type coord) )


(defun dist (point1 point2)
  (sqrt (+ (square (- (coord-x point1) (coord-x point2)))
           (square (- (coord-y point1) (coord-y point2))))))

(defun square (x) (* x x))
4

1 回答 1

0

Lisp 家族中语言的美妙之处在于(相对)统一的语法。就像您square通过 write(square n)*by调用函数一样(* n1 n2 ...),您调用dist,它接受两个参数 with, (dist point1 point2)。在上下文中,这可能类似于:

(let ((point1 (make-coord …))
      (point2 …))
  (dist point1 point2))
于 2013-09-22T22:49:09.770 回答