Hi - The Tupelo library has some nice "spy" debugging tools available
<https://github.com/cloojure/tupelo#expression-debugging>.  ​
Full docs are available on GitHub pages:
http://cloojure.github.io/doc/tupelo/index.html

My favorite one is `spyx` (short for "spy expression"). It is used like
this:

(it-> 1                 ; tupelo.core/it->
      (spyx (inc it))
      (* 2 it)); (inc it) => 2     ; the expression is used as the label4


​A newer version (not in the README yet!) can turn any `let` expression
into a `spy` debugging tool.  In a code fragment like this:


      (let [module-hid         (tf/add-tree-hiccup yang-ast-hiccup)
            module-bush-before (tf/hid->bush module-hid)
            >>                 (tx-module module-hid)
            module-bush-after  (tf/hid->bush module-hid) ]



just replace `let` with `let-spy-pretty`


      (let-spy-pretty
           [module-hid         (tf/add-tree-hiccup yang-ast-hiccup)
            module-bush-before (tf/hid->bush module-hid)
            >>                 (tx-module module-hid)
            module-bush-after  (tf/hid->bush module-hid)
            ]

to get printed output like this:

module-hid =>
:5d77d6d3a49b09624ca8e8c9f9c975228a212d03

module-bush-before =>
[{:tag :module}
 [{:tag :identifier} "calculator"]
 [{:tag :namespace}
  [{:tag :string} "http://brocade.com/ns/calculator";]]
 [{:tag :contact}
  [{:tag :string} "Alan Thompson <atho...@brocade.com>"]]
 [{:tag :description}
  [{:tag :string} "YANG spec for a simple RPN calculator"]]
 [{:tag :revision}
  [{:tag :iso-date} "2017-04-01"]
  [{:tag :description} [{:tag :string} "Prototype 1.0"]]]
 [{:tag :rpc}
  [{:tag :identifier} "add"]
  [{:tag :description} [{:tag :string} "Add 2 numbers"]]
  [{:tag :input}
   [{:tag :leaf}
    [{:tag :identifier} "x"]
    [{:tag :type} [{:tag :identifier} "decimal64"]]]
   [{:tag :leaf}
    [{:tag :identifier} "y"]
    [{:tag :type} [{:tag :identifier} "decimal64"]]]]
  [{:tag :output}
   [{:tag :leaf}
    [{:tag :identifier} "result"]
    [{:tag :type} [{:tag :identifier} "decimal64"]]]]]]

>> =>
{:attrs {:tag :rpc, :name :add},
 :kids
 [:f0212a89632b49ac693979b01f40ba330a081288
  :6e6cf8dee634c80046510d8ab161d7e32ca60456]}

module-bush-after =>
[{:tag :module,
  :name :calculator,
  :namespace "http://brocade.com/ns/calculator";,
  :contact "Alan Thompson <atho...@brocade.com>",
  :description "YANG spec for a simple RPN calculator",
  :revision "2017-04-01"}
 [{:tag :rpc, :name :add}
  [{:tag :input}
   [{:type :decimal64, :name :x}]
   [{:type :decimal64, :name :y}]]
  [{:tag :output} [{:type :decimal64, :name :result}]]]]


Alan


On Sat, Jun 3, 2017 at 4:57 PM, Bill Piel <b...@billpiel.com> wrote:

> Hi lvh,
>
> Author of sayid here. Couple questions:
>
> - would you want the debug traces to be available only during development?
> Or does this need to run in production too?
> - what editor are you using? or does the solution need to be
> editor-agnostic?
>
> Also, FWIW, Sayid does have features that allow you get to at the raw
> captured data, not just the printed output. These two commands are
> available from the sayid buffer.
>
> > d -- def value to $s/*
> > g -- generate instance expression and put in kill ring
>
> https://www.youtube.com/watch?v=ipDhvd1NsmE#t=13m (13:00)
>
> Bill
>
> On Saturday, June 3, 2017 at 11:11:09 AM UTC-4, Laurens Van Houtven wrote:
>>
>> And, immediately after I sent this, I remembered clojure.tools.trace;
>> which also looks pretty similar :)
>>
>> On Sat, Jun 3, 2017 at 9:57 AM, lvh <_...@lvh.io> wrote:
>>
>>> Hi,
>>>
>>>
>>> I have a piece of code that takes a limited subset of Clojure as
>>> queries, e.g.:
>>>
>>> (not= (some gnarly expr) (some-other-gnarly-expr))
>>>
>>> It also produces the result, which is interesting when the query is just
>>> (some gnarly expr) and the result itself is interesting, but less
>>> interesting when the top level is  a =/not= call and the result is just
>>> "true" or "false". I would like to report intermediate values, because they
>>> tell you _why_ something failed.
>>>
>>> So far, I have a few ideas (thanks to clojure slack for adding a few):
>>>
>>> * coerce taoensso.timbre/spy, which roughly does what I want, into
>>> giving me results as data instead of capturing stdout; potentially just
>>> using with-out-str as a first pass. Problem: some of these expressions are
>>> quite meaty, and this doesn't give me the option of pretty-printing them.
>>> * manually instrument the expression with a macro like
>>> taoensso.timbre/spy, except one that stores values.
>>> * coerce sayid into doing the same thing (https://bpiel.github.io/sayid/).
>>> sayid looks like it mostly does what I want, except it's heavily focused on
>>> editor integration, and I really just want the data.
>>> * https://github.com/dgrnbrg/spyscope, which appears to do something
>>> generally similar to what sayid does, but is also really focused on
>>> editors/human fueled debugging (primarily using reader macros as an
>>> interface and stdout as output). Obviously reader macros are easy to work
>>> around :)
>>>
>>> Is there anything useful I'm missing, or am I better off just hacking it
>>> together myself?
>>>
>>> I'm already using specter, so instrumenting forms is not a big deal.
>>> It's always nice to get values as data instead of random strings, but the
>>> final target is humans, so eventually something is going to get printed.
>>>
>>>
>>> thanks in advance,
>>> lvh
>>>
>>>
>> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to