├── .gitignore ├── LICENCE.txt ├── README.org ├── cl-debug-print-test.asd ├── cl-debug-print.asd ├── cl-syntax-debug-print.asd ├── src └── cl-debug-print.lisp ├── syntax.lisp └── tests └── cl-debug-print.lisp /.gitignore: -------------------------------------------------------------------------------- 1 | *.fasl 2 | *.dx32fsl 3 | *.dx64fsl 4 | *.lx32fsl 5 | *.lx64fsl 6 | *.x86f 7 | *~ 8 | .#* -------------------------------------------------------------------------------- /LICENCE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 Satoshi Imai 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | * cl-debug-print 2 | 3 | A reader macro package for debug printing. 4 | 5 | ** Install 6 | 7 | When install by Roswell, 8 | 9 | #+begin_src 10 | ros install masatoi/cl-debug-print 11 | #+end_src 12 | 13 | ** Usage 14 | 15 | #+BEGIN_SRC lisp 16 | (ql:quickload :cl-debug-print) 17 | (debug-print:use-debug-print) 18 | 19 | ;;; Debug print 20 | 21 | (defun fact (n) 22 | (if (= #>n 0) 23 | 1 24 | (* n #>(fact (1- n))))) 25 | 26 | (fact 10) 27 | 28 | ;; N => 10 29 | ;; N => 9 30 | ;; N => 8 31 | ;; N => 7 32 | ;; N => 6 33 | ;; N => 5 34 | ;; N => 4 35 | ;; N => 3 36 | ;; N => 2 37 | ;; N => 1 38 | ;; N => 0 39 | ;; (FACT (1- N)) => 1 40 | ;; (FACT (1- N)) => 1 41 | ;; (FACT (1- N)) => 2 42 | ;; (FACT (1- N)) => 6 43 | ;; (FACT (1- N)) => 24 44 | ;; (FACT (1- N)) => 120 45 | ;; (FACT (1- N)) => 720 46 | ;; (FACT (1- N)) => 5040 47 | ;; (FACT (1- N)) => 40320 48 | ;; (FACT (1- N)) => 362880 49 | 50 | ;;; Debug push 51 | 52 | (defun fact2 (n) 53 | (if (= n 0) 54 | 1 55 | (* n #!(fact2 (1- n))))) 56 | 57 | (fact2 10) 58 | ;; => 3628800 59 | 60 | ;;; Debug push results are stored to *dbg* 61 | 62 | cl-debug-print:*dbg* 63 | ;; => (362880 40320 5040 720 120 24 6 2 1 1) 64 | 65 | ;;; Clearing debug push list 66 | 67 | (cl-debug-print:clear-dbg) 68 | 69 | cl-debug-print:*dbg* 70 | ;; => nil 71 | #+END_SRC 72 | 73 | *** Configure variables 74 | 75 | #+begin_src lisp 76 | ;;; Setting destination stream (default value is *standard-output*) 77 | 78 | (setf cl-debug-print:*destination* *error-output*) 79 | 80 | ;;; Setting for using DESCRIBE instead of mere value (default value is nil) 81 | 82 | (setf cl-debug-print:*use-describe* t) 83 | 84 | #>'sin 85 | 86 | ;; 'SIN => COMMON-LISP:SIN 87 | ;; [symbol] 88 | ;; 89 | ;; SIN names a compiled function: 90 | ;; Lambda-list: (NUMBER) 91 | ;; Declared type: (FUNCTION (NUMBER) 92 | ;; (VALUES 93 | ;; (OR (SINGLE-FLOAT -1.0 1.0) 94 | ;; (DOUBLE-FLOAT -1.0d0 1.0d0) 95 | ;; (COMPLEX SINGLE-FLOAT) (COMPLEX DOUBLE-FLOAT)) 96 | ;; &OPTIONAL)) 97 | ;; Derived type: (FUNCTION (T) 98 | ;; (VALUES 99 | ;; (OR (SINGLE-FLOAT -1.0 1.0) 100 | ;; (DOUBLE-FLOAT -1.0d0 1.0d0) 101 | ;; (COMPLEX DOUBLE-FLOAT) (COMPLEX SINGLE-FLOAT)) 102 | ;; &OPTIONAL)) 103 | ;; Documentation: 104 | ;; Return the sine of NUMBER. 105 | ;; Known attributes: foldable, flushable, unsafely-flushable, movable, recursive 106 | ;; Source file: SYS:SRC;CODE;IRRAT.LISP 107 | #+end_src 108 | -------------------------------------------------------------------------------- /cl-debug-print-test.asd: -------------------------------------------------------------------------------- 1 | #| 2 | This file is a part of cl-debug-print project. 3 | |# 4 | 5 | (defsystem "cl-debug-print-test" 6 | :defsystem-depends-on ("prove-asdf") 7 | :author "" 8 | :license "" 9 | :depends-on ("cl-debug-print" 10 | "prove") 11 | :components ((:module "tests" 12 | :components 13 | ((:test-file "cl-debug-print")))) 14 | :description "Test system for cl-debug-print" 15 | 16 | :perform (test-op (op c) (symbol-call :prove-asdf :run-test-system c))) 17 | -------------------------------------------------------------------------------- /cl-debug-print.asd: -------------------------------------------------------------------------------- 1 | #| 2 | This file is a part of cl-debug-print project. 3 | |# 4 | 5 | (defsystem "cl-debug-print" 6 | :version "0.2.0" 7 | :author "Satoshi Imai" 8 | :license "MIT" 9 | :depends-on ("cl-syntax") 10 | :components ((:module "src" 11 | :components 12 | ((:file "cl-debug-print")))) 13 | :description "A reader-macro for debug print" 14 | :long-description 15 | #.(read-file-string 16 | (subpathname *load-pathname* "README.org")) 17 | :in-order-to ((test-op (test-op "cl-debug-print-test")))) 18 | -------------------------------------------------------------------------------- /cl-syntax-debug-print.asd: -------------------------------------------------------------------------------- 1 | (in-package :cl-user) 2 | 3 | (defpackage :cl-syntax-debug-print-asd 4 | (:use :cl :asdf)) 5 | (in-package :cl-syntax-debug-print-asd) 6 | 7 | (defsystem "cl-syntax-debug-print" 8 | :version "0.1.0" 9 | :author "Satoshi Imai" 10 | :license "MIT" 11 | :description "CL-Synax reader system for cl-debug-print" 12 | :depends-on ("cl-syntax" "cl-debug-print") 13 | :components 14 | ((:file "syntax"))) 15 | -------------------------------------------------------------------------------- /src/cl-debug-print.lisp: -------------------------------------------------------------------------------- 1 | (defpackage cl-debug-print 2 | (:nicknames :debug-print) 3 | (:use #:cl 4 | #:cl-syntax 5 | #:named-readtables) 6 | (:export #:debug-print 7 | #:debug-print-reader 8 | #:debug-push 9 | #:debug-push-reader 10 | #:*use-describe* 11 | #:*destination* 12 | #:*dbg* 13 | #:clear-dbg 14 | #:debug-print-syntax 15 | #:use-debug-print)) 16 | (in-package :cl-debug-print) 17 | 18 | (defvar *use-describe* nil 19 | "When *USE-DESCRIBE* is true, describe is used for debug prints.") 20 | 21 | (defvar *destination* nil 22 | "*DESTINATION* allows to configure destination stream for debug prints.") 23 | 24 | (defvar *dbg* nil 25 | "*DBG* is a list, and using DEBUG-PUSH(#!) will be pushed to this list. 26 | To clear this variable, use the CLEAR-DBG function.") 27 | 28 | (defun debug-print (pre-exp exp) 29 | (let ((*destination* (or *destination* *standard-output*))) 30 | (if *use-describe* 31 | (format *destination* "~A => ~A~%" pre-exp 32 | (with-output-to-string (s) 33 | (describe exp s))) 34 | (format *destination* "~A => ~S~%" pre-exp exp))) 35 | exp) 36 | 37 | (defun debug-print-reader (stream char1 char2) 38 | (declare (ignore char1 char2)) 39 | (let ((read-data (read stream t nil t))) 40 | `(debug-print (quote ,read-data) ,read-data))) 41 | 42 | (defun clear-dbg () 43 | (setf *dbg* nil)) 44 | 45 | (defun debug-push (obj) 46 | (push obj cl-debug-print:*dbg*) 47 | obj) 48 | 49 | (defun debug-push-reader (stream char1 char2) 50 | (declare (ignore char1 char2)) 51 | (let ((read-data (read stream t nil t))) 52 | `(debug-push ,read-data))) 53 | 54 | (defsyntax debug-print-syntax 55 | (:merge :standard) 56 | (:dispatch-macro-char #\# #\> #'debug-print-reader) 57 | (:dispatch-macro-char #\# #\! #'debug-push-reader)) 58 | 59 | (defun use-debug-print () 60 | (cl-syntax:use-syntax debug-print-syntax) 61 | t) 62 | -------------------------------------------------------------------------------- /syntax.lisp: -------------------------------------------------------------------------------- 1 | (in-package #:cl-user) 2 | 3 | (syntax:define-package-syntax :debug-print 4 | (:merge :standard) 5 | (:dispatch-macro-char #\# #\> #'cl-debug-print:debug-print-reader)) 6 | -------------------------------------------------------------------------------- /tests/cl-debug-print.lisp: -------------------------------------------------------------------------------- 1 | (defpackage cl-debug-print-test 2 | (:use :cl 3 | :cl-debug-print 4 | :prove)) 5 | (in-package :cl-debug-print-test) 6 | 7 | ;; NOTE: To run this test file, execute `(asdf:test-system :cl-debug-print)' in your Lisp. 8 | 9 | (plan nil) 10 | 11 | ;; blah blah blah. 12 | 13 | (finalize) 14 | --------------------------------------------------------------------------------