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

current status of documentation #694

Merged
merged 23 commits into from
Aug 13, 2024
Merged

current status of documentation #694

merged 23 commits into from
Aug 13, 2024

Conversation

DaddyWesker
Copy link
Contributor

@DaddyWesker DaddyWesker commented May 20, 2024

Subj

get-doc/help! for empty doesn't work just like for =.
For empty help! gives

Function empty (type (-> %Undefined%)) No documentation
[()]

For =:

Function = (type (-> $t#48 $t#48 Atom)) No documentation
[()]

Another problem is duplicating functions. There are several of them. I've tried to create some documentation which aggregate both variants but I wasn't been able to do it for every function. For example, @param. It uses two type notations. In the second one @param have two inputs but I don't get which ones. Same goes to @return.

Since currently documentation is duplicating for such functions even if there is only one documentation I'm currently commenting documentation for those funcs.

For some unknown to me reason, same problem doesn't occur for @doc-formal though it has two type notations as well.

help! also doesn't show anything for (@kind function) and (@kind atom).

@DaddyWesker DaddyWesker requested a review from vsbogd May 20, 2024 07:42
lib/src/metta/runner/stdlib.metta Outdated Show resolved Hide resolved
lib/src/metta/runner/stdlib.metta Outdated Show resolved Hide resolved
lib/src/metta/runner/stdlib.metta Show resolved Hide resolved
lib/src/metta/runner/stdlib.metta Outdated Show resolved Hide resolved
lib/src/metta/runner/stdlib.metta Outdated Show resolved Hide resolved
lib/src/metta/runner/stdlib.metta Outdated Show resolved Hide resolved
lib/src/metta/runner/stdlib.metta Outdated Show resolved Hide resolved
lib/src/metta/runner/stdlib.metta Outdated Show resolved Hide resolved
lib/src/metta/runner/stdlib.metta Outdated Show resolved Hide resolved
lib/src/metta/runner/stdlib.metta Outdated Show resolved Hide resolved
@DaddyWesker
Copy link
Contributor Author

DaddyWesker commented May 29, 2024

@vsbogd
There are two types of problems. First, for some reason get-doc/help for some reason returns "No documentation" for some functions. Second, for &self metta hangs for some time and then segmentation fault. I've tried to understand what is a reason behind this. For the second problem, segmentation fault could be triggered using such code:

!(let $top-space (mod-space! top)
    (unify $top-space (@doc &self $desc (@params $params) $ret)
        $ret
        Err))

So segmentation fault happening on this step. Unfortunately, I don't know why.

As for the first problem, it is somewhat tricky. For example, two functions: xor and or. Both have two input parameters and output. Here is docs:

(@doc or
  (@desc "Logical disjunction of two arguments")
  (@params (
    (@param "First argument")
    (@param "Second argument")))
  (@return "True if any of input arguments is True, False - otherwise"))
 
(@doc xor
  (@desc "Exclusive disjunction of two arguments")
  (@params (
    (@param "First argument")
    (@param "Second argument")))
  (@return "Return values are the same as logical disjunction, but when both arguments are True xor will return False"))

So, those docs are kinda similar, but !(help! xor) gives:

Function xor: (-> Bool Bool Bool) Exclusive disjunction of two arguments
Parameters:
  (type Bool) First argument
  (type Bool) Second argument
Return: (type Bool) Return values are the same as logical disjunction, but when both arguments are True xor will return False
[()]

and !(help! or) gives:

Function or (type (-> Bool Bool Bool)) No documentation
[()]

I don't get it. If I'll use this code once again

!(let $top-space (mod-space! top)
    (unify $top-space (@doc or $desc (@params $params) $ret)
        $ret
        Err))

I'll get Err. So for some reason unify doesn't work for or.

Moreover, if I'll add doc for or inside script I'm launching, everything will be fine. Unfortunately, I don't know inner structure of metta so I can't understand what is happening here.

Comment on lines 131 to 134
; TODO: get-doc not showing docs for following two functions (@kind function) and (@kind atom) for some reason.
(@doc (@kind function)
(@desc "Used for documentation purposes. Shows type of entity to be documented. (@kind function) in this case")
(@return "(@kind function) entity"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
; TODO: get-doc not showing docs for following two functions (@kind function) and (@kind atom) for some reason.
(@doc (@kind function)
(@desc "Used for documentation purposes. Shows type of entity to be documented. (@kind function) in this case")
(@return "(@kind function) entity"))
(@doc (@kind function)
(@desc "Used for documentation purposes. Shows type of entity to be documented. (@kind function) in this case"))

Copy link
Contributor Author

@DaddyWesker DaddyWesker Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vsbogd
For some reason in minimal metta for (@kind function ) documentation returned two times:

Atom (@kind function): (%Undefined% (-> Atom Atom)) Used for documentation purposes. Shows type of entity to be documented. (@kind function) in this case
Atom (@kind function): DocKindFunction Used for documentation purposes. Shows type of entity to be documented. (@kind function) in this case
[(), ()]

In regular metta everything is fine. Also, @kind atom works fine in both metta.

lib/src/metta/runner/stdlib.metta Outdated Show resolved Hide resolved
(@param "Second argument")))
(@return "Returns True if both arguments are True, False - otherwise"))

; TODO: get-doc/help! not working for or
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luketpeterson I would like to check it with you. Analysis shows that it doesn't work because when this module is loaded or token is replaced by Rust implementation. But when user executes !(help or) or is replaced by the Python implementation it is the reason why documentation is not returned (Python and Rust implementations do not match).

In MettaMod code I see the following snippet:

if !no_stdlib {
if let Some(stdlib_mod_id) = metta.0.stdlib_mod.get() {
new_mod.import_all_from_dependency(*stdlib_mod_id, metta.get_mod_ptr(*stdlib_mod_id)).unwrap();
}
}

To me it sounds like one one implementation of the stdlib tokens should be loaded: either Rust or Python but looks like in fact we have two of them at the same time. Is it made by intention or it is a bug?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is a bug and we can fix it then it could fix the documentation behaviour. On the other hand this operation duality can mean that we need separate documentation for Rust grounded atoms and Python grounded atoms.

Copy link
Contributor

@luketpeterson luketpeterson Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me it sounds like one one implementation of the stdlib tokens should be loaded

The python stdlib could be changed to not load corelib, but that's not what it currently does. Right now it loads corelib (which is the Rust stdlib), and overwrites / supersedes certain definitions from corelib with its own definitions.

But I feel like this docs issue is only tangentially related to that question.

My first thought is: If the Python hyperon/stdlib.py is providing alternative versions of these operation atoms, it should also be responsible to provide documentation for them.

But my second thought is: Since the changes made a few months ago make the type conversion for grounded atoms much more flexible and add powerful arithmetic & logic ops to corelib, can we get rid of these op atoms in hyperon/stdlib.py altogether? Although certainly in a different PR from this one?

Copy link
Collaborator

@vsbogd vsbogd Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, to me these last two changes you are talking about are also a orthogonal to each other.

One question is about documentation and here I am starting to think that it is more logical to have documentation for the grounded atom inside its implementation like we having grounded atom's type. Thus this documentation is always available from the atom itself. It contradicts to the way I wanted to see grounded atoms in future (I mean for the grounded function I would like to represent both types and docs inside atomspace and keep only function implementation as a native code) but on the other hand it is better to have internally aligned representation and switch to another one in one step.

Second question is should we have duplicates of the operations in Python stdlib. The idea was to keep Python stdlib working with native data in a native way. Taking into account calling Python method anyway requires cloning vales I doubt implementing operations on numbers and boolean values in Python makes much sense . Thus may be we could get rid of duplicates in Python (Strings serialization is still not implemented thus we cannot fully remove duplicates at the moment probably)

@vsbogd
Copy link
Collaborator

vsbogd commented Jun 10, 2024

@DaddyWesker
Copy link
Contributor Author

@DaddyWesker could you please also add docs for operations added by #698 and here https://github.com/trueagi-io/hyperon-experimental/pull/691/files#diff-0cc50ef2951a3babcc599e443e489112ae31c6f8e76da2d22b97160ad85d9a32

Probably done. Please check.

@DaddyWesker DaddyWesker marked this pull request as ready for review June 13, 2024 05:29
@DaddyWesker DaddyWesker requested a review from vsbogd June 13, 2024 05:30
@vsbogd
Copy link
Collaborator

vsbogd commented Aug 12, 2024

@DaddyWesker please merge my review comments in DaddyWesker#3

vsbogd and others added 2 commits August 13, 2024 08:38
Fix documentation for minimal MeTTa standard library
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

Successfully merging this pull request may close these issues.

3 participants