How to handle conflicting functions between 2 packages

The issue is popping very often with DynamicalSystems.ji package now, here’s a sample

of using …

julia> IntervalBox(-2..2, -2..2)
WARNING: both ChaosTools and GLMakie export ".."; uses of it in module Main must be qualified
ERROR: UndefVarError: `..` not defined
Stacktrace:
 [1] top-level scope
   @ REPL[614]:1

there was another function name too poincaresos,

help?> poincaresos
search: poincaresos brainscan_poincaresos interactive_poincaresos interactive_poincaresos_scan poincaremap PoincareMap poincare_map

  poincaresos(A::AbstractStateSpaceSet, plane; kwargs...) → P::StateSpaceSet

  Calculate the Poincaré surface of section of the given dataset with the given plane by performing linear interpolation betweeen points that sandwich the
  hyperplane.

  Argument plane and keywords direction, warning, save_idxs are the same as in PoincareMap.



  ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

  poincaresos(ds::CoupledODEs, plane, T = 1000.0; kwargs...) → P::StateSpaceSet

  Return the iterations of ds on the Poincaré surface of section with the plane, by evolving ds up to a total of T. Return a StateSpaceSet of the points that are
  on the surface of section.

  This function initializes a PoincareMap and steps it until its current_crossing_time exceeds T. You can also use trajectory with PoincareMap to get a sequence
  of N::Int points instead.

  The keywords Ttr, save_idxs act as in trajectory. See PoincareMap for plane and all other keywords.

now if I want to use the second function how will i proceed? second one is from chaostools.poincaresos even if I explicitly give that, it’s not working. How to over come these

@hisacro, welcome to Julia Discourse.

I don’t think the .. is connected to the poincaresos method calling at all. So let me separate them as follows:

.. case

This is a tricky one because of the infix nature of the function.

I think the only straightforward solution might be to use import for the package from which you don’t use the .. function and using for the other one.

In your case, the qualified usage means something like IntervalBox.:(..)(-2, 2), which is messing greatly with the ergonimics. So, I’d stick with only performing using on one of the packages and use import for the other.

Keep in mind that if you want to avoid the qualified access for various functions in the package you only imported by import, you can always do: using Package: f1, f2.

I hope the following example helps:

import GLMakie
using GLMakie: Figure, Axis, scatter!
using ChaosTools

In the above scenario you’ll be able to properly use your .. function (as infix) and also easily use functions from GLMakie (you can extend the list as needed). There is no longer a conflict related to .. function (in this scenario we are opting for using the .. from the ChaosTools package).

I hope this makes sense.

poincaresos function

Here you do not have two poincaresos functions. You only have more than one method for this function.

You actually do not need to do anything else than call the function with the appropriate arguments. Julia will figure out which method to use based on the arguments you use.

myf(a::Int, b::Int) = a + b
myf(a::Float64, b::Float64) = a - b

myf(20, 10)
# will return 30

my(20.0, 10.0)
# will return 10.0

You can go into more depth about the methods here.

3 Likes

For the package that you import with import, instead of with using, you can assign its .. operator to a constant. If you pick one of the supported names, it can still be an infix operator. Something like this:

import A

# This is a Unicode symbol, it's not just three periods.
const … = A.:(..)

A REPL example with other operators:

julia> const ⊕ = +
+ (generic function with 189 methods)

julia> 3 ⊕ 2
5

Regrettably, one has to look at the source to see what are all the supported operators, e.g.:

3 Likes

yeah, sorry about that… It’s because the devs of Interval Arithemetic Root finding and the devs of Makie using different package definition for the interval type. I asked a couple of times that this should change, as there is no real reason for two packages to define Interval type, but it hasn’t happened yet. So until it happens we are stuck with this problem…

3 Likes

News from the (1.10) future: it’s possible to see these without having to visit github and browse through reams of femtolisp:

julia-1.10> join(filter(s -> length(s) ==1, 
    Base.JuliaSyntax._kind_names))

which will show you many hundreds of strange glyphs, many of which you could use as operators.

Such as :

help?> ⅋
"⅋" can be typed by \upand<tab>

Checking it out:

julia-1.10> Base.operator_precedence(:⅋)
12

julia-1.10> Base.isbinaryoperator(:⅋)
true

julia-1.10> Base.isoperator(:⅋)
true

julia-1.10> ⅋(x, y) = print("let's upand $x $y")
⅋ (generic function with 1 method)

julia-1.10> ⅋(2, 3)
let's upand 2 3
3 Likes