-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
log-once
- A macro for printing an expression a limited number of times
#3
Comments
It might be better to use syntax-local-lift-expression rather than embed a phase-1 value. |
You're completely right! I've just gone through and updated my main post to use that procedure - I've also shifted my old code to the 'previous revisions' section at the bottom. Thank you for spotting that! |
Thank you for your contribution! If you haven’t already please take the time to fill in the form https://forms.gle/Z5CN2xzK13dfkBnF7 Bw |
Macro
The purpose of this macro was to make it possible to view a sample of values within tight loops - rather than being inundated with thousands of lines of irrelevant data. It achieves this by providing a variety of tools that can be used to constrain what is logged down to what actually interests the observer.
The set of macros have gone through many revisions as I have become more knowledgable regarding syntax and syntax-parse, with this iteration making use of
~?
and~@
, as well as the excellent...
from syntax-parse.Example
Before and After
The macro replaces patterns of code that would look something like this:
I wrote the original edition of this macro while I was comparatively new to racket. It was my first ernest attempt at a macro.
While the original version of the macro is lost (it used a hash map of the syntax info to track what had been logged)
I do have this previous revision:
It was here that I realised that I could declare a variable during phase 1 and store a reference to it for use later in phase 0.
As a direct reference to the variable would simply put the value within the expanded syntax, I put a reference to a function instead, the function being responsible for mutating the variable.
This varient of the macro featured an improved implementation of
log-defs
, which makes handy use of syntax-parse's ellipsis to repeat patterns of syntax. I also exchanged references to procedures for references to a box, which I considered more idiomatic to racket.The box and procedures has subsequently been replaced by usage of
syntax-local-lift-expression
, which eliminates the need for phase 1 variables to be referenced in phase 0 (thank you toyjqww6
for this suggestion!).As there is no further need to interface between phases then the procedures
should-run?!
&stop-logging?!
can take no arguments - instead relying on embedded references to other lifted identifiers.Licence
I confirm that the code is under the same license as the Racket language, and associated text is under Creative Commons Attribution 4.0 International License
Contact
The text was updated successfully, but these errors were encountered: