【发布时间】:2014-11-17 18:37:33
【问题描述】:
我编写了一个 LISP 程序,它通过 princ 和 write-line 运算符将一些输出数据写入 CommonLisp 控制台。如何重做它将输出数据写入文件? 我的程序:
(defun printTriangle()
(
progn
(let((countx xmin)(county ymin)(koeff1 nil)(koeff2 nil))
(loop
(cond ((> county ymax)(return "")))
(loop
(cond ((> countx xmax)(return "")))
(if (equal (- countx (car(nth (- (length line1)1) line1))) 0)(setf divisionByZeroKoef1 1)(setf divisionByZeroKoef1 0))
(if (equal (- countx (cadar line1)) 0)(setf divisionByZeroKoef2 1)(setf divisionByZeroKoef2 0))
(if (or(equal divisionByZeroKoef1 1)(equal divisionByZeroKoef2 1))
(
progn
(setf koeff1 (- county (cadr(nth (- (length line1)1) line1))))
(setf koeff2 (- county (caar line1)))
(if (or
(and
(and(>= (- koeff1 koeffHyp1)-0.8)(<= (- koeff1 koeffHyp1)0.8))
(and(>= (- koeff2 koeffHyp2)-0.8)(<= (- koeff2 koeffHyp2)0.8))
(<= ymin county)
(>= ymax county)
(<= xmin countx)
(>= xmax countx)
)
(equal (memberList line1 (list countx county)) 1)
)
(princ "*")
(princ "-")
)
)
(
progn
(setf koeff1 (/(- county (cadr(nth (- (length line1)1) line1)))(- countx (car(nth (- (length line1)1) line1)))))
(setf koeff2 (/(- county (caar line1))(- countx (cadar line1))))
(if (or
(and
(and(>= (- koeff1 koeffHyp1)-0.8)(<= (- koeff1 koeffHyp1)0.8))
(and(>= (- koeff2 koeffHyp2)-0.8)(<= (- koeff2 koeffHyp2)0.8))
(<= ymin county)
(>= ymax county)
(<= xmin countx)
(>= xmax countx)
)
(equal (memberList line1 (list countx county)) 1)
)
(princ "*")
(princ "-")
)
)
)
(setf countx (+ countx 1))
)
(setf countx xmin)
(write-line "")
(setf county (+ county 1))
)
(print "The triangle is draw!")
)
)
)
除了princ和write-line,我可以通过哪些运算符?
【问题讨论】:
-
您的大部分代码与该问题无关。您可能希望使用较短的示例。
标签: file-io stream lisp common-lisp