-
Notifications
You must be signed in to change notification settings - Fork 5
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
get rid of the fourth argument of maketerm
, type
#36
Comments
It's planned to be supported by Metatheory.jl 3.0, but can also be aggregated with |
Type and metadata have quite specific meanings. Metadata is layered on top of data, the hash of an object for example does not depend on its metadata but depends on the type it's like "data in the shadows". Type is used to represent the typed S-expression. I'm fine with doing something that makes sense for other packages and also does not make it awkward for SU. |
If
Can't you just change that, seems like an implementation detail?
What's a "typed S-expression"? |
I don't think so? The same expression but of a different type is a different expression. |
if an S-expression is |
Thanks everyone for working to make this package better. I have a few thoughts on this, I hope they help the discussion.
If this is true, perhaps the type should also be an expression itself, as Alessandro suggests. I think packages that are not SU often just do:
I've gotten away without the In many ways,
just as we would write
SU is able to cache the latter analysis without the help of TermInterface.
If I am writing a generic symbolic transformation, I would just ask whether we really want to define "code that respects the TermInterface" to mean that my transform needs to correctly manipulate I think that already there's some confusion about what Another question: Could you help me define symtype for my use case? I do keep track of the types of things, but I am able to do it outside of a I'll conclude with a few proposals for alternate ways to handle symtype
|
Nice ideas @willow-ahrens. 1. and 2. sound OK, but wouldn't the compiler specialize a new method for each kwarg provided? that's likely avoidable. See #35 from @nsajko I do agree that Moreover, most instances of function TermInterface.maketerm(::Type{<:BasicSymbolic}, head, args, type, metadata)
basicsymbolic(head, args, type, metadata)
end Which could just become struct SymbolicMetadata
symtype::Type
# whatever...
end
function TermInterface.maketerm(::Type{<:BasicSymbolic}, head, args, metadata::Union{Nothing,SymbolicMetadata})
stype = isnothing(metadata) ? nothing : metadata.symtype
basicsymbolic(head, args, stype, metadata)
end |
I mean, that's already what happens in function basicsymbolic(f, args, stype, metadata)
if f isa Symbol
error("$f must not be a Symbol")
end
T = stype
if T === nothing
T = _promote_symtype(f, args)
end
if T <: LiteralReal
Term{T}(f, args, metadata=metadata)
elseif T <: Number && (f in (+, *) || (f in (/, ^) && length(args) == 2)) && all(x->symtype(x) <: Number, args)
res = f(args...)
if res isa Symbolic
@set! res.metadata = metadata
end
return res
else
Term{T}(f, args, metadata=metadata)
end
end WDYT? I'm in favor of deleting |
Is this actually correct? How do you have the type in the hash if it's in the metadata? Since part of the identity of a value is its type, I don't quite see how you can get this correct. |
There's a few ways we could do this:
|
As Willow also says in the first point, I don't see why should metadata be excluded from consideration in |
What happens when the metadata is modified to add a key after the symbol is constructed, as is common? Won't that change the hash? |
In SymbolicUtils.jl,
here the symbolic object |
Okay if it's already in the type parameters then it's redundant information and the symtype function should just use: @assume_effects :total __parameterless_type(T)=Base.typename(T).wrapper
parameterless_type(x) = parameterless_type(typeof(x))
parameterless_type(x::Type) = __parameterless_type(x) I don't quite get why @shashi had it in the values and the parameters then. |
Also, please no 0 ver... I'm just going to do the v1.0 release right here so we can maintain this. |
In SymbolicUtils.jl, the numeric type We do exclude
|
Originally posted by @nsajko in #25 (comment)
The fourth argument,
type
, seems like it's not generally useful for expressions, and redundant with the next argument,metadata
. Is there any reason why it should exist in this interface?I notice that the in-development version of Metatheory.jl that supports the current TermInterface.jl always ignores both
type
andmetadata
, and so will my package. EDIT: actually my package does usemetadata
for some types.Was
type
only introduced to make things slightly more convenient for the SymbolicUtils.jl implementation?The text was updated successfully, but these errors were encountered: