Last active
October 8, 2017 01:55
-
-
Save wobh/b313809dbb377298c56f42a84ad20ba7 to your computer and use it in GitHub Desktop.
When print returns the output-stream ...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun pr (obj &optional (str *standard-output*)) | |
(princ o str) | |
str) | |
;;; ... it becomes possible to chain `pr' expressions together: | |
;; (pr "!" (pr "world" (pr " " (pr "hello")))) | |
;;; This means, with a little convenience function (like `format'): | |
(defun rp (str obj) | |
(pr obj str)) | |
;;; a sequence of objects can be printed as a reduction. | |
#| | |
CL-USER> (reduce #'rp '("hello" " " "world" "!") :initial-value *standard-output*) | |
hello world! | |
#<SWANK/GRAY::SLIME-OUTPUT-STREAM {10024777B3}> | |
CL-USER> (reduce #'pr '("hello" " " "world" "!") :initial-value *standard-output* :from-end t) | |
!world hello | |
#<SWANK/GRAY::SLIME-OUTPUT-STREAM {10024777B3}> | |
|# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment