I currently have a lot of print statements in SML code, and I'm traversing a very large tree, so it takes a while for all the print statements to be printed, but right now I don't want to see any print statements and just want to see it run as fast as possible. But I don't want to comment all the prints because I later need them again to debug something else.
So I just want to be able to temporarily disable them for this run of the code.
I'm using the SML/NJ compiler.
As the first line in your code put the definition
fun print x = ();
Then -- your code will still work but the prints will do nothing.
Delete that line when you want to re-enable print.
Related
I am using the deepdiff function to find the difference between 2 dictionaries, which gives the output as: A = {'dictionary_item_added': set(["root['mismatched_element']"])}. How to print just 'mismatched_element'?
Try this:
set_item = A['dictionary_item_added'].pop()
print set_item[set_item.find("['")+2 : set_item.find("']")]
The first line gets the element from the set, the second removes the [] and everything around them, and prints.
This code does the specific task you asked for, but it's hard to generalize the solution without a more generalized question..
I'd like to print a string, either const char* or std::string, using lldb so that it is human readable. Most importantly, \n's would be printed as a newline. Does anyone know how to do this? I tried the advice given for gdb in this post, however it doesn't seem to work with lldb.
Edit: I'm aware that you can issue the print myString command to print the string, however it doesn't format newline characters (at least not by default):
Most of the time you want to see the literal contents of your strings, so the default lldb behavior for print is correct. However, it would be useful to have a format option to "render" the output in the same way the standard libraries would do a string. That's basically what the gdb "printf" command is. Please file a bug with the lldb.llvm.org bug reporter asking for this.
Just like with gdb, you can get the standard library to render the text for you:
(lldb) expr (void) printf("Some text\nMore text\nEven more text\n")
Some text
More text
Even more text
(lldb)
I cast it to void in this case because I didn't care about the return value, and it makes it harder to see the text.
As was pointed out in the post you referred to, if your output is not going to a terminal somewhere, that isn't helpful, so some explicit "render the output" option would be a good idea as well. But that should only happen if you attach to, rather than run, your program in the debugger.
I have files with lines of input which I compare to eachother. I have simplified my code alot and obviously it isnt in working python but the main bits of important are the first line for iteration and the else clause, both of which are the ones used. The rest are just to show I wish to continue on with the data if it passes the Comparison code.
for read1, read2 in itertools.izip(input_file1, input_file2):
{CODE FOR COMPARISON}
if matched:
Worked = read1+read2
else:
print to output_file2
break
{CONTINUE ANALYSIS OF 'Worked'}
print Worked to output_file1
I assumed adding a print to file and break would solve the issue however it doesn't break the for loop so the next iteration occurs, it just breaks it. Is there anyway to use a command like break to move onto the next iteration of lines in both input files?
Thanks,
Tom
Is there anyway to use a command like break to move onto the next iteration of lines in both input files?
You are looking for the continue statement rather than the break statement:
break exits the loop whereas continue just moves onto the next iteration
for read1, read2 in itertools.izip(input_file1, input_file2):
{CODE FOR COMPARISON}
if matched:
Worked = read1+read2
else:
print to output_file2
continue
{CONTINUE ANALYSIS OF 'Worked'}
print Worked to output_file1
See
https://docs.python.org/2/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops
I have a question concerning Stata. I'm executing a loop in which there might be an error. Whether the error occurs depends on the data at hand. Unfortunately I do not know exactly how the data, which my code is used for, looks like. I only know the variables which are in the data. So I use the command capture to let my do-file run even if an error occurs. But if I use this command, Stata also suppresses the output if the command sometimes works in my loop. Of course, that is not what I want.
My command looks like:
capture list year JCage`x' numberfirmsage`x' AvSizeAge`x'
and is part of a loop. So what can I do in order to solve the problem?
The help for capture tells you that this is done by capture noisily.
I am writing sml programs which run on SML/NJ and MLton (not interactive). When I use print statements in the the sml file, SML/NJ always adds
val it = () : unit
to the output, which clutters up the output. MLton does not do this.
Is there a way to remove this output? I have tried CM_VERBOSE=false, which did not help.
Running SML/NJ v110.73.
Without examples of the code that produces this, it is a bit hard to help, however it seems that your "issues" are somewhat related to this question.
In summary, remember to bind all result values to something, such that the it variable don't get assigned to the result:
val _ = print "fooo"