-
Notifications
You must be signed in to change notification settings - Fork 61
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
current state of pretty print #771
Conversation
Fixed return value
I've checked, code works if launched like this:
|
@@ -88,6 +88,8 @@ def __call__(self, command_a, *args_a): | |||
self.init_sdk() | |||
if command == 'get_service_callers': | |||
return args[0].generate_callers() | |||
if command == 'get_service_callers_text': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there was no need to expose this function to metta
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, i removed those lines.
def generate_callers_text(self): | ||
# TODO: pretty print | ||
return "\n".join([repr(e) for e in self.generate_callers()]) | ||
res = "\n".join([repr(e) for e in self.generate_callers()]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see pretty-print is used here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad. It was used for a while, but then I've removed by mistake. Added.
# TODO: pretty print | ||
return "\n".join([repr(e) for e in self.generate_callers()]) | ||
res = "\n".join([repr(e) for e in self.generate_callers()]) | ||
return [ValueAtom(res)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no need to wrap the result of this function into atom since it is supposed as a pure Python function, and it can be called via py-dot from metta
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
@@ -137,9 +139,105 @@ def get_service_messages(self): | |||
def get_operation_atom(self): | |||
return OperationAtom(self.service_details[1], self) | |||
|
|||
def __pretty_print__(self, input_str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pretty-print was supposed for adding to stdlib, but maybe it can remain here for now....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I wasn't been aware of this. Where should I place it?
@@ -137,9 +139,105 @@ def get_service_messages(self): | |||
def get_operation_atom(self): | |||
return OperationAtom(self.service_details[1], self) | |||
|
|||
def __pretty_print__(self, input_str): | |||
list_of_functions = ["if", "match", "let", "let*", "unify", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is special about these functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are functions which could have several inner brackets inside their body. Probably I could forget some functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's about just nested expressions like (* (- $x $y) (- $x $y))
? What is the substantial difference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect that it is problematic to detect nested brackets in your approach, because you try to reformat a textual representation, so you need to re-parse it. If you'd started with atoms, it could be simpler...
Okay, so I've rewrote pretty_print so it takes atoms as input not string. Below are some examples of how pretty_print prints atoms into string. @Necr0x0Der check if it is fine with you (when you have time of course).
|
@@ -139,14 +143,58 @@ def get_service_messages(self): | |||
def get_operation_atom(self): | |||
return OperationAtom(self.service_details[1], self) | |||
|
|||
def __pretty_print_atoms__(self, input_atoms): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move this function out of ServiceCall
and wouldn't introduce len_threshold
and current_len
as its fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, where to move this function? As i remember, you've proposed to move it to stdlib. Should i place it there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can keep it in the same file for now. Just move it out of the class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Necr0x0Der Done.
ValueAtom(f'unknown command {repr(command_a)}'))] | ||
|
||
len_threshold = 50 | ||
current_len = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will happen when the function is called twice? Will current_len
behave correctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it should be set to 0 (line 158 sets it to 0 after every subatom was processed). I'll check just to be sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Necr0x0Der I've checked (though I needed to do some changes to init_sdk since snet-sdk was updated and now its init is slightly different, probably i need to make new pr for those changes?) and current_len is 0 on the start of pretty print. And it can be seen on line 154.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, but still... Are they used only in pretty_print_atoms
and its subfunctions? In this case, it's better to not declare them as global
, but rather introduce them in pretty_print_atoms
and use nonlocal
for them in subfunctions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try this out. I haven't been aware of nonlocal
. Of course it would be better to introduce them inside function I just wasn't been able to make them work correctly. If nonlocal
will help, I'll push changes tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Necr0x0Der Okay, it works. Thank you. I've pushed new commit with changes regarding current_len and threshold
current_len and threshold into function
Examples of pretty_prints in current state: