((section 2 "Outdated egg!" (p "This is an egg for CHICKEN 4, the unsupported old release.  You're almost certainly looking for " (int-link "/eggref/5/debug" "the CHICKEN 5 version of this egg") ", if it exists.") (p "If it does not exist, there may be equivalent functionality provided by another egg; have a look at the " (link "https://wiki.call-cc.org/chicken-projects/egg-index-5.html" "egg index") ". Otherwise, please consider porting this egg to the current version of CHICKEN.")) (section 2 "debug" (p "Some trivial debugging macros") (toc) (section 3 "Abstract" (p "According to " (link "http://books.google.com/books?id=nneBa6-mWfgC&lpg=PA227&ots=gEvyGdNW3u&dq=%22thou%20shalt%20put%20printf%22&pg=PA227#v=onepage&q=%22thou%20shalt%20put%20printf%22&f=false" "Joe Armstrong") ", \"The great gods of programming said, 'Thou shalt put " (tt "printf") " statements in your program at the point where you think it’s gone wrong, recompile, and run it.'\"")) (section 3 "Documentation" (section 4 (tt "debug?") (def (sig (parameter "debug? → #t" (id debug?))) (p "`debug?' turns on or off debugging output, depending on whether it is set to #t or #f; respectively.") (highlight scheme "(define debug? (make-parameter #t))"))) (section 4 (tt "trace") (def (sig (syntax "(trace f) → unspecified" (id trace))) (p "Trace the input to and output from a function.") (dl (dt (tt "f")) (dd "The function to be traced")) (highlight scheme "(define-syntax\n  trace\n  (er-macro-transformer\n    (lambda (expression rename compare)\n      (match-let\n        (((_ f) expression))\n        (let ((%set! (rename 'set!))\n              (%lambda (rename 'lambda))\n              (%call-with-values (rename 'call-with-values))\n              (%apply (rename 'apply))\n              (%format (rename 'format))\n              (%values (rename 'values))\n              (%let (rename 'let))\n              (%f (rename 'f))\n              (%when (rename 'when))\n              (%debug? (rename 'debug?)))\n          `(,%when\n            (,%debug?)\n            (,%let\n             ((,%f ,f))\n             (,%set!\n              ,f\n              (,%lambda\n               x\n               (,%format (current-error-port) \";; Arguments to ~a: ~a~%\" ',f x)\n               (,%let\n                ((return-values\n                   (,%call-with-values\n                    (,%lambda () (,%apply ,%f x))\n                    (,%lambda x x))))\n                (,%format\n                 (current-error-port)\n                 \";; Values from ~a: ~a~%\"\n                 ',f\n                 return-values)\n                (,%apply ,%values return-values)))))))))))"))) (section 4 (tt "debug") (def (sig (syntax "(debug expressions) → unspecified" (id debug))) (p "Debug the expressions to stderr by pretty-printing each expression and their evaluations.") (dl (dt (tt "expressions")) (dd "The expressions to be debugged")) (highlight scheme "(define-syntax\n  debug\n  (syntax-rules\n    ()\n    ((_ x ...)\n     (with-output-to-port\n       (current-error-port)\n       (lambda ()\n         (when (debug?)\n               (pp `(,(if (or (boolean? 'x)\n                              (char? 'x)\n                              (number? 'x)\n                              (string? 'x)\n                              (vector? 'x))\n                        x\n                        `(x =>\n                            ,(handle-exceptions\n                               exn\n                               (let ((message\n                                       ((condition-property-accessor 'exn 'message) exn))\n                                     (arguments\n                                       ((condition-property-accessor 'exn 'arguments)\n                                        exn)))\n                                 (format\n                                   \"Error: ~a~a\"\n                                   message\n                                   (if (null? arguments)\n                                     \"\"\n                                     (format\n                                       \": ~a\"\n                                       (string-join (map ->string arguments) \", \")))))\n                               x)))\n                     ...))))))))"))) (section 4 (tt "debug-priority") (def (sig (parameter "debug-priority → prio/debug" (id debug-priority))) (p "The priority associated with " (tt "debug/syslog")) (highlight scheme "(define debug-priority (make-parameter prio/debug))"))) (section 4 (tt "debug/syslog") (def (sig (syntax "(debug/syslog expressions) → unspecified" (id debug/syslog))) (p "Debug to syslog.") (dl (dt (tt "expressions")) (dd "The expressions to debug (cf. `debug' supra)")) (highlight scheme "(define-syntax\n  debug/syslog\n  (ir-macro-transformer\n    (lambda (expression rename inject)\n      `(let ((port (make-syslog-port)))\n         (with-error-output-to-port\n           port\n           (lambda ()\n             (when (debug?)\n                   (debug ,@(cdr expression))\n                   (flush-output port))))))))")))) (section 3 "About this egg" (section 4 "Author" (p (int-link "/users/klutometis" "Peter Danenberg"))) (section 4 "Repository" (p (link "https://github.com/klutometis/debug"))) (section 4 "License" (p "BSD")) (section 4 "Dependencies" (ul (li (int-link "hahn")) (li (int-link "matchable")) (li (int-link "setup-helper")) (li (int-link "syslog")))) (section 4 "Versions" (dl (dt (link "https://github.com/klutometis/debug/releases/tag/0.1" "0.1")) (dd "Version 0.1") (dt (link "https://github.com/klutometis/debug/releases/tag/0.1.1" "0.1.1")) (dd "Version 0.1.1") (dt (link "https://github.com/klutometis/debug/releases/tag/0.1.2" "0.1.2")) (dd "BSD") (dt (link "https://github.com/klutometis/debug/releases/tag/0.2" "0.2")) (dd "Add a `debug?'-parameter.") (dt (link "https://github.com/klutometis/debug/releases/tag/0.3" "0.3")) (dd "Add exception-guard; document.") (dt (link "https://github.com/klutometis/debug/releases/tag/0.3.1" "0.3.1")) (dd "Add \"Error: ...\"") (dt (link "https://github.com/klutometis/debug/releases/tag/0.3.2" "0.3.2")) (dd "Add arguments in errors.") (dt (link "https://github.com/klutometis/debug/releases/tag/0.3.3" "0.3.3")) (dd "Don't do arguments if we don't have to.") (dt (link "https://github.com/klutometis/debug/releases/tag/0.3.4" "0.3.4")) (dd "With a note about cock-utils") (dt (link "https://github.com/klutometis/debug/releases/tag/0.3.5" "0.3.5")) (dd "Add test-exit.") (dt (link "https://github.com/klutometis/debug/releases/tag/0.3.6" "0.3.6")) (dd "Disable an offending test.") (dt (link "https://github.com/klutometis/debug/releases/tag/0.3.7" "0.3.7")) (dd "Self-evaluating scalars") (dt (link "https://github.com/klutometis/debug/releases/tag/0.3.8" "0.3.8")) (dd "Fix tests") (dt (link "https://github.com/klutometis/debug/releases/tag/0.3.9" "0.3.9")) (dd "Fix debug/syslog.") (dt (link "https://github.com/klutometis/debug/releases/tag/0.3.10" "0.3.10")) (dd "Default-priority -> debug-priority") (dt (link "https://github.com/klutometis/debug/releases/tag/0.3.11" "0.3.11")) (dd "Use setup-helper-cock.") (dt (link "https://github.com/klutometis/debug/releases/tag/0.3.12" "0.3.12")) (dd "Remove the dependency on setup-helper-cock.") (dt (link "https://github.com/klutometis/debug/releases/tag/0.3.13" "0.3.13")) (dd "Drop setup-helper-cock.") (dt (link "https://github.com/klutometis/debug/releases/tag/0.3.14" "0.3.14")) (dd "Use ports, don't merely import it.") (dt (link "https://github.com/klutometis/debug/releases/tag/0.3.15" "0.3.15")) (dd "Use hahn."))) (section 4 "Colophon" (p "Documented by " (int-link "/egg/hahn" "hahn") ".")))))