1

I've written a LISP-program, it writes some output data to the CommonLisp console via princ and write-line operators. How to redo it to it writes output data to the file? My program:

(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!")
        )
    )
)

Which of operators can I past instead of princ and write-line?

1
  • 1
    Most of your code was not relevant for the question. You might want to use shorter examples. Commented Nov 17, 2014 at 21:12

1 Answer 1

4

You can redirect stdout by changing the dynamic variable:

(with-open-file (*standard-output*
                 "my-file-name.txt"
                 :direction :output
                 :if-exists :supersede)
  (print-triangle))

You can change your print-triangle to take an output-stream.

(defun print-triangle (&optional out)
  (princ "output" out))

(with-open-file (handle
                 "my-file-name.txt"
                 :direction :output
                 :if-exists :supersede)
  (print-triangle handle))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.