Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional Printing #9

Open
nadavgover opened this issue Jul 12, 2020 · 0 comments
Open

Conditional Printing #9

nadavgover opened this issue Jul 12, 2020 · 0 comments

Comments

@nadavgover
Copy link

Hi! I suggest a new idea, conditional printing.

Current state

(mate/dreduce + [1 3 5 7 9]) (as an example) will print all the stages to stdout.

Problem

  1. Printing is time consuming
  2. The developer writes the code especially for debugging
  3. Need to change the code for production in order not to have the time consuming printing

Suggested Solution

What if the developer will not have to change the production code and in the same time will not suffer from printing? Sounds good to be true? Sounds like conditional printing!
The whole idea is that during runtime we can decide whether or not to print. I suggest 3 methods to do that:

  1. Printing Levels:
    Every macro can take an optional printing level ∈ #{0 1 2 3 4 5}. This level must be >= mate/*min-level* for printing to occur.
    For example:
(mate/dreduce {:level 3} + [1 3 5 7 9])  ; Only activates printing when (>= 3 *min-level*) 

A developer can setmate/min-level by mate/set-min-level!

  1. Namaspace Filtering:
    Prints can be elided or filtered by the namespace in which they occur.
    For example, a developer can call
(mate\set-ns-patterns! {:whitelist #{"foo.bar.*"} :blacklist #{"bar.foo.*"}})
  1. Arbitrary Runtime Conditions:
    Each macro supports an optional arbitrary test expression:
(mate/dreduce {:when my-cond?} + [1 3 5 7 9])  ; Only activates printing when `my-cond?` is truthy

That's it, thanks :)
This idea and suggested solution was inspired by tufte profiler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant