@@ -157,7 +157,7 @@ function unsorted_arguments(x::BasicSymbolic)
157
157
if isadd (x)
158
158
for (k, v) in x. dict
159
159
push! (args, applicable (* ,k,v) ? k* v :
160
- similarterm (k, * , [k, v]))
160
+ maketerm (k, * , [k, v]))
161
161
end
162
162
else # MUL
163
163
for (k, v) in x. dict
@@ -192,6 +192,9 @@ isadd(x) = isa_SymType(Val(:Add), x)
192
192
ispow (x) = isa_SymType (Val (:Pow ), x)
193
193
isdiv (x) = isa_SymType (Val (:Div ), x)
194
194
195
+ TermInterface. head (:: BasicSymbolic ) = basicsymbolic
196
+ TermInterface. children (t:: BasicSymbolic ) = cons (operation (t), arguments (t))
197
+
195
198
# ##
196
199
# ## Base interface
197
200
# ##
@@ -528,28 +531,11 @@ end
528
531
529
532
unflatten (t) = t
530
533
531
- """
532
- similarterm(t, f, args, symtype; metadata=nothing)
533
-
534
- Create a term that is similar in type to `t`. Extending this function allows packages
535
- using their own expression types with SymbolicUtils to define how new terms should
536
- be created. Note that `similarterm` may return an object that has a
537
- different type than `t`, because `f` also influences the result.
538
-
539
- ## Arguments
540
-
541
- - `t` the reference term to use to create similar terms
542
- - `f` is the operation of the term
543
- - `args` is the arguments
544
- - The `symtype` of the resulting term. Best effort will be made to set the symtype of the
545
- resulting similar term to this type.
546
- """
547
- similarterm (t:: Symbolic , f, args; metadata= nothing ) =
548
- similarterm (t, f, args, _promote_symtype (f, args); metadata= metadata)
549
- similarterm (t:: BasicSymbolic , f, args,
550
- symtype; metadata= nothing ) = basic_similarterm (t, f, args, symtype; metadata= metadata)
534
+ function TermInterface. maketerm (:: Type{<:BasicSymbolic} , head, args, type, metadata)
535
+ basicsymbolic (first (args), args[2 : end ], type, metadata)
536
+ end
551
537
552
- function basic_similarterm (t, f, args, stype; metadata= nothing )
538
+ function basicsymbolic ( f, args, stype, metadata)
553
539
if f isa Symbol
554
540
error (" $f must not be a Symbol" )
555
541
end
@@ -647,6 +633,36 @@ function to_symbolic(x)
647
633
x
648
634
end
649
635
636
+ """
637
+ similarterm(x, op, args, symtype=nothing; metadata=nothing)
638
+
639
+ """
640
+ function similarterm (x, op, args, symtype= nothing ; metadata= nothing )
641
+ Base. depwarn (""" `similarterm` is deprecated, use `maketerm` instead.
642
+ See https://github.com/JuliaSymbolics/TermInterface.jl for details.
643
+ The present call can be replaced by
644
+ `maketerm(typeof(x), $(head (x)) , [op, args...], symtype, metadata)`""" , :similarterm )
645
+
646
+ TermInterface. maketerm (typeof (x), callhead (x), [op, args... ], symtype, metadata)
647
+ end
648
+
649
+ # Old fallback
650
+ function similarterm (T:: Type , op, args, symtype= nothing ; metadata= nothing )
651
+ Base. depwarn (" `similarterm` is deprecated, use `maketerm` instead." *
652
+ " See https://github.com/JuliaSymbolics/TermInterface.jl for details." , :similarterm )
653
+ op (args... )
654
+ end
655
+
656
+ export similarterm
657
+
658
+
659
+ """
660
+ callhead(x)
661
+ Used in this deprecation cycle of `similarterm` to find the `head` argument to
662
+ `maketerm`. Do not implement this, or use `similarterm` if you're using this package.
663
+ """
664
+ callhead (x) = typeof (x)
665
+
650
666
# ##
651
667
# ## Pretty printing
652
668
# ##
0 commit comments