344ee2fa239e

Add `prl`
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Mon, 21 Nov 2016 11:10:49 +0000
parents 21296e2bf834
children 66fc93caa1c6
branches/tags (none)
files DOCUMENTATION.markdown losh.lisp package.lisp

Changes

--- a/DOCUMENTATION.markdown	Thu Nov 17 12:44:46 2016 +0000
+++ b/DOCUMENTATION.markdown	Mon Nov 21 11:10:49 2016 +0000
@@ -339,6 +339,28 @@
 
   
 
+### `PRL` (macro)
+
+    (PRL &REST ARGS)
+
+Print `args` labeled and readably.
+
+  Each argument form will be printed, then evaluated and the result printed.
+  One final newline will be printed after everything.
+
+  Returns the last result.
+
+  Examples:
+
+    (let ((i 1)
+          (l (list 1 2 3)))
+      (prl i (second l)))
+    ; =>
+    i 1
+    (second l) 2
+
+  
+
 ### `SHUT-UP` (macro)
 
     (SHUT-UP
--- a/losh.lisp	Thu Nov 17 12:44:46 2016 +0000
+++ b/losh.lisp	Mon Nov 21 11:10:49 2016 +0000
@@ -1342,6 +1342,30 @@
   (finish-output)
   (first args))
 
+(defmacro prl (&rest args)
+  "Print `args` labeled and readably.
+
+  Each argument form will be printed, then evaluated and the result printed.
+  One final newline will be printed after everything.
+
+  Returns the last result.
+
+  Examples:
+
+    (let ((i 1)
+          (l (list 1 2 3)))
+      (prl i (second l)))
+    ; =>
+    i 1
+    (second l) 2
+
+  "
+  `(prog1
+     (progn ,@(mapcar (lambda (arg) `(pr ',arg ,arg)) args))
+     (terpri)
+     (finish-output)))
+
+
 (defun bits (n size &optional (stream t))
   "Print the bits of the `size`-bit two's complement integer `n` to `stream`.
 
--- a/package.lisp	Thu Nov 17 12:44:46 2016 +0000
+++ b/package.lisp	Mon Nov 21 11:10:49 2016 +0000
@@ -159,6 +159,7 @@
   (:documentation "Utilities for figuring out what the hell is going on.")
   (:export
     :pr
+    :prl
     :bits
     :shut-up
     :dis