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

request for new functions: isvariable and variablename #38

Open
nsajko opened this issue May 31, 2024 · 4 comments
Open

request for new functions: isvariable and variablename #38

nsajko opened this issue May 31, 2024 · 4 comments

Comments

@nsajko
Copy link
Contributor

nsajko commented May 31, 2024

I want to be able to convert any TermInterface.jl expression to one of the expression types defined by my CallableExpressions.jl package. However, I don't think that TermInterface.jl on its own currently makes that possible. The problem is that, for leaves of the expression tree, I'm not able to:

  • tell variables apart from constants

  • convert a foreign variable type to a native variable type, for that I need to associate the variable with a name, as each variable is determined by a single Symbol value in CallableExpressions.jl

I think it'd make sense for TermInterface.jl to introduce two additional functions:

  • isvariable (name subject to bikeshedding, of course): isvariable(x) should be true when x is a single variable, and it should be false when x is a constant or an expression (neither constant expressions nor variable expressions count as "a variable" here)

  • variablename(x) should return an object representing a unique name for the variable, ideally convertible to Symbol

Thoughts?

@0x0f0f0f
Copy link
Member

0x0f0f0f commented Jun 2, 2024

I think it's generally a good idea, but we don't definitely want to define isvariable(x::Symbol) = true, because in Expr we won't know when a symbol is used as a variable or not. It depends on the context. I suggest to not include it in TermInterface.jl because it really does depend on the language being used.

@0x0f0f0f
Copy link
Member

0x0f0f0f commented Jun 2, 2024

In Metatheory.jl I'm having

# TODO: document
Base.@inline maybe_quote_operation(x::Union{Function,DataType}) = nameof(x)
Base.@inline maybe_quote_operation(x::Symbol) = x

@nsajko
Copy link
Contributor Author

nsajko commented Jun 2, 2024

we don't definitely want to define isvariable(x::Symbol) = true

Agree.

@ChrisRackauckas
Copy link
Member

I think this is fine. Since it's an interface addition it would be non-breaking to add.

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

No branches or pull requests

3 participants