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

Added help() shell function #150

Merged
merged 14 commits into from
May 30, 2024
Merged

Added help() shell function #150

merged 14 commits into from
May 30, 2024

Conversation

Vardan2009
Copy link
Contributor

help() displays help info for each data type

Part of #8

@Almas-Ali
Copy link
Member

How this will work with user defined objects?

@Almas-Ali Almas-Ali requested review from Almas-Ali and removed request for Almas-Ali May 29, 2024 17:06
@Vardan2009
Copy link
Contributor Author

Didn't think of that. I think users can define a custom__help_repr__ function in their classes to return a string

@Almas-Ali
Copy link
Member

Almas-Ali commented May 29, 2024

Can we dynamically generate the help from object? Example:

class AClass {
    "AClass a simple OOP class."

    fun __contructor__(num1) {
        "The constructor"
        this.num1 = num1
    }

    fun squre() {
        # some hidden logics
        return this.num1 ^ 2
    }

    fun add(n1, n2) {
        # some hidden logics
        return n1 + n2
    }
}

Output

Help on int object:

class AClass()
 |  
 |  AClass a simple OOP class.
 | 
 | a = AClass()
 | 
 | null
 |  
 |  Methods defined here:
 |  
 |  squre()
 |      return this.num1 ^ 2
 |  
 |  add(n1, n2)
 |      return n1 + n2
 |  

Here in this example, help(obj) will generate documentation like this format for builtin classes and user defined classes. We need to manage this or similar syntax.

@Vardan2009
Copy link
Contributor Author

Can we dynamically generate the help from object?

Is there a way to get all the methods and what they return dynamically?

@Almas-Ali
Copy link
Member

Can we dynamically generate the help from object?

Is there a way to get all the methods and what they return dynamically?

Not exists till now?

@Vardan2009
Copy link
Contributor Author

So when defining a method in a class, it can also store that info somewhere, that might also help making the dir function later

@Almas-Ali
Copy link
Member

So when defining a method in a class, it can also store that info somewhere, that might also help making the dir function later

Yeah, you can create like that.

@Almas-Ali
Copy link
Member

What do you think @angelcaru ?

@Vardan2009
Copy link
Contributor Author

Vardan2009 commented May 29, 2024

I'm currently working on it, here is the result so far

Help on object Test:

class Test
| local_value = "value"
| fun __constructor__()
|        returns something
|
| fun test(test,s)
|        returns something

How can I check what the function returns if this is a dynamic typed language? Maybe we can put something else there, like a description for the method?

@Almas-Ali
Copy link
Member

How can I check what the function returns if this is a dynamic typed language? Maybe we can put something else there, like a description for the method?

Showing description in return?
Okay, fine for now.

@Vardan2009
Copy link
Contributor Author

how should the descriptions be written? Maybe a local variable in each function like:

fun test(test,s){
   __desc = "Description for method test"
   # Do something
}

@angelcaru
Copy link
Contributor

Maybe a built-in function? Like:

fun test(test, s) {
    # Do something
}
set_doc(test, "Description for method test")

Because I don't see how you would get the value for a __desc variable without actually running the function

@Vardan2009
Copy link
Contributor Author

Oh... right

@Almas-Ali
Copy link
Member

I think we can do it like Python. In the first line, if we have a string, then set it to description else put empty.

@Vardan2009
Copy link
Contributor Author

Vardan2009 commented May 29, 2024

I think I got it working, here
Input

class Test
{
    fun __constructor__(){

    }

    fun test(test,s){
        "Description for method test"
        print("tesst")
    }
}

help(Test())

Output

Help on object Test:

class Test
| fun __constructor__()
|        [No Description]
|
| fun test(test,s)
|        Description for method test
|

@Almas-Ali
Copy link
Member

This will be like print(help(Test)) or print(help(Test()))

@Vardan2009
Copy link
Contributor Author

it will be just help(Test()), and yes, it always has to get the instance to the class, not the class itself

@angelcaru
Copy link
Contributor

it always has to get the instance to the class, not the class itself

That seems inconvenient. What if the constructor has arguments?

@Vardan2009
Copy link
Contributor Author

Yeah... I will try to get it working to accept both instances and classes

@angelcaru
Copy link
Contributor

It should also work on standalone functions. Right now it only works on classes

@Vardan2009
Copy link
Contributor Author

So, something like this?

Help on function test
| fun test(args)
|       desc

@Almas-Ali
Copy link
Member

Almas-Ali commented May 29, 2024

A new thing. If I want to get the output from help() it returns the object. But, it should return null.

fun some() -> null
a = help(some)
print(a) # <function some>

@Vardan2009 Vardan2009 requested a review from Almas-Ali May 29, 2024 19:46
@Almas-Ali
Copy link
Member

Little spacing will make this look pretty.

Help on object Test:

class Test
| property1 = "Hello, World!"
| fun __constructor__()
|	[No Description]
| fun func1(arg1, arg2 = true)
|	Description for func1
| fun func2(arg1 = null)
|	Description for func2
| fun no_description()
|	[No Description]

Help on object Test:

class Test
| property1 = "Hello, World!"
| fun __constructor__()
|	[No Description]
| fun func1(arg1, arg2 = true)
|	Description for func1
| fun func2(arg1 = null)
|	Description for func2
| fun no_description()
|	[No Description]

Help on function standalone
| fun standalone(arg1, arg2 = true)
|	This is a standalone function

@Almas-Ali
Copy link
Member

Previous output was nice.

@Vardan2009
Copy link
Contributor Author

Vardan2009 commented May 29, 2024

Is this good?

Help on object Test:

class Test
| property1 = "Hello, World!"
|
| fun __constructor__()
|       [No Description]
|
| fun func1(arg1, arg2)
|       Description for func1
|
| fun func2(arg1)
|       Description for func2
|
| fun no_description()
|       [No Description]
|

Help on object Test:

class Test
| property1 = "Hello, World!"
|
| fun __constructor__()
|       [No Description]
|
| fun func1(arg1, arg2)
|       Description for func1
|
| fun func2(arg1)
|       Description for func2
|
| fun no_description()
|       [No Description]
|

Help on function standalone:

| fun standalone(arg1, arg2)
|       This is a standalone function

@Almas-Ali
Copy link
Member

Add spacing in also property. Example:

Help on object Test:

class Test
|
| property1 = "Hello, World!"
|
| fun __constructor__()
|       [No Description]
|
| fun func1(arg1, arg2)
|       Description for func1
|
| fun func2(arg1)
|       Description for func2
|
| fun no_description()
|       [No Description]
|

Help on object Test:

class Test
|
| property1 = "Hello, World!"
|
| fun __constructor__()
|       [No Description]
|
| fun func1(arg1, arg2)
|       Description for func1
|
| fun func2(arg1)
|       Description for func2
|
| fun no_description()
|       [No Description]
|

@Almas-Ali
Copy link
Member

It is running the method or class to get its inner string!! This is now expected.

@Vardan2009
Copy link
Contributor Author

?

@Almas-Ali
Copy link
Member

?

Check this. It is running the Test class to get it's inner descriptions.

class Test
{
    property1 = "Hello, World!"
    print(property1)
    val = 324 + true

    fun __constructor__()
    {

    }

    fun func1(arg1, arg2=true)
    {
        "Description for func1"
    }

    fun func2(arg1=null)
    {
        "Description for func2"
        return true
    }

    fun no_description() {
        return null
    }
}

help(Test)

@angelcaru
Copy link
Contributor

No it's not? It's running the Test class to create the class. That's how it works

@Vardan2009
Copy link
Contributor Author

The descriptions get collected during the parsing. After the LBRACE, when it encounters a string, it sets it as it's description, then continues the parsing.

Copy link
Member

@Almas-Ali Almas-Ali left a comment

Choose a reason for hiding this comment

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

It's fine as an initial implementation. We will work on it, if we found any issue later on.

Thank you for your contribution. 🥇

@Almas-Ali Almas-Ali merged commit a0ac8b8 into radon-project:master May 30, 2024
1 check passed
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