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

Handling of qualified operations #234

Closed
olynch opened this issue Aug 16, 2024 · 4 comments
Closed

Handling of qualified operations #234

olynch opened this issue Aug 16, 2024 · 4 comments

Comments

@olynch
Copy link
Collaborator

olynch commented Aug 16, 2024

This is me adding my two cents about qualified operations, as related to #209.

I think that the behavior of maybe_quote_operation in Metatheory.jl is confusing, and breaks lexical scoping.

I would prefer to have something like:

struct FuncRef
  # Fully-qualified module name
  fqmn::Vector{Symbol}
  name::Symbol
end

struct TypeRef
  fqmn::Vector{Symbol}
  name::Symbol
end

maybe_quote_operation(x::Function) = FuncRef([fullname(parentmodule(x))...], nameof(x))
maybe_quote_operation(x::DataType) = TypeRef([fullname(parentmodule(x))...], nameof(x))

Similarly, I think that the @rule macro should work differently. Rather than fully constructing the rule at macro-expansion time, the macro

@rule (~x + ~y) == (~y + ~x)

should expand to something like

Rule(App(+, [Var(1, :x), Var(2, :y)]) == App(+, [Var(2, :y), Var(1, :x)]))

Thus, the identity of + is given by whatever it is bound to in the current lexical scope, rather than simply treating it as :(+). This would be more in line with how SymbolicUtils works, and it would naturally solve #209.

@olynch
Copy link
Collaborator Author

olynch commented Aug 16, 2024

Or really, why are we even quoting? Couldn't we just store the functions in the constant table directly? It seems like functions/types actually hash reasonably well.

@olynch
Copy link
Collaborator Author

olynch commented Aug 16, 2024

OK, I see the problem: rewriting of Exprs would break with this approach.

How many things downstream rely on rewriting Exprs vs. rewriting TermInterface stuff?

@olynch
Copy link
Collaborator Author

olynch commented Aug 16, 2024

Ah, I didn't carefully read src/Syntax.jl; I didn't understand that you do in fact resolve symbols in the current module! Neat. I'm going to close this.

@olynch olynch closed this as completed Aug 16, 2024
@0x0f0f0f
Copy link
Member

0x0f0f0f commented Aug 19, 2024

OK, I see the problem: rewriting of Exprs would break with this approach.

How many things downstream rely on rewriting Exprs vs. rewriting TermInterface stuff?

@olynch They are both TermInterface. This was already discussed a while ago and it took us ages with the Symbolics.jl team to find a decent TermInterface that supported both quoted and unquoted operations :)

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

2 participants