Print output into a file or not print output?

后端 未结 3 1467
臣服心动
臣服心动 2021-01-13 13:51

I\'d like to save or ignore outputs when I execute a specific function in lisp. I use Emacs and CCL. For example,

(defun foo (x) (format t \"x = ~s~%\" x))
         


        
3条回答
  •  野的像风
    2021-01-13 14:21

    I'm not sure I understand your question, but the second argument to format is a stream. If you set it to t it prints to standard output, but you can also set it to an open file.

    So something like this would allow you to select where the output goes:

    ;;output to file:
    (setf *stream* (open "myfile" :direction :output
                                  :if-exists :supersede)
    
    ;;alternative to output to standard output:
    ;;(setf *stream* t)
    
    (defun foo (x) (format *stream* "x = ~s~%" x))
    
    (foo 10)
    (close *stream*) ;; only if output sent to a file
    

提交回复
热议问题