Skip to content

Instantly share code, notes, and snippets.

@wobh
Last active October 8, 2017 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wobh/b313809dbb377298c56f42a84ad20ba7 to your computer and use it in GitHub Desktop.
Save wobh/b313809dbb377298c56f42a84ad20ba7 to your computer and use it in GitHub Desktop.
When print returns the output-stream ...
(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