GithubHelp home page GithubHelp logo

plumpmath / pr-foobar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from luxbock/pr-foobar

0.0 0.0 0.0 136 KB

Pretty print debugging macros for Clojure

License: Eclipse Public License 1.0

Clojure 100.00%

pr-foobar's Introduction

pr-foobar

pr-foobar is a collection of print debugging macros combining the functionality of AlexBaranosky/print-foo with cldwalker/table.

The following macros are provided:

pr-> pr->> pr-let pr-when-let pr-if-let pr-if pr-if-not pr-when pr-when-not pr-cond pr-and pr-or

Example

user> (pr-let [a (map inc (range 5))
               b (filter even? a)
               c (reduce + b)]
        [a b c])
┌────────┬───────────────────────┐
│ let    │ value                 │
├────────┼───────────────────────┤
│ a      ╎ (1 2 3 4 5)           │
│ b      ╎ (2 4)                 │
│ c      ╎ 6                     │
│ RESULT ╎ [(1 2 3 4 5) (2 4) 6] │
└────────┴───────────────────────┘
[(1 2 3 4 5) (2 4) 6]
user>

Exceptions are handled gracefully, so using pr-foobar is a fast way to get an idea when your code is failing:

user> (pr->> (range 5) rest first dec (/ 1) str)
┌──────────────────────────────────┬───────────────────────────────────────────────────────────────┐
│ ->> clojure.lang.LazySeq@1b554e1 │ step                                                          │
├──────────────────────────────────┼───────────────────────────────────────────────────────────────┤
│ rest                             ╎ (1 2 3 4)                                                     │
│ first                            ╎ 1                                                             │
│ dec                              ╎ 0                                                             │
│ (/ 1)                            ╎ #<ArithmeticException java.lang.ArithmeticException: Divid... │
└──────────────────────────────────┴───────────────────────────────────────────────────────────────┘
ArithmeticException Divide by zero  clojure.lang.Numbers.divide (Numbers.java:156)

Installation and Usage

Add:

Clojars Project

as a dependency. You may wish to add it to your ~/.lein/profiles.clj or ~/.profile.boot files to have it available with all of your projects.

To use it:

(use 'pr.foobar)

Or you might consider using a tool like vinyasa to have it required and available in all of your namespaces.

Limitations

You should be careful about using pr-foobar with side-effectful code, as the results of an expression may be evaluated multiple times in the macro call.

Doesn't play well with infinite lazy sequences.

License

Copyright © Olli Piepponen 2015

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

pr-foobar's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.