Is there Way to know methods/functions of classes(modules/functions)

For example,
I’ve defined a array or anything,


a = [1,2,3,4,5]

as we have methods opposite order.

If I want to know what are the methods could be used in this array. looking help on a doesn’t gives any methods to see.
search: a any all abs ans Any axes atan asin asec any! all! acsc acot acos abs2

No documentation found in any defined datatypes or functions.


  a is of type Array{Int64,1}.

  Summary
  ≡≡≡≡≡≡≡≡≡

  mutable struct Array{Int64,1} <: DenseArray{Int64,1}

  Supertype Hierarchy
  ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

  Array{Int64,1} <: DenseArray{Int64,1} <: AbstractArray{Int64,1} <: Any

It would be great if I would know some code completion on methods of some datatypes.


Also,
I want to know how julia pushes/appends arrays of array like this [1, 2, 3, 4, 5, [1,2,3]]
I cant use push!(a, [1,2,3]) giving error MethodError. although
this worked

a = [1,2,3,4,5]
append!(a, [1,2,3])

but appends like this [1,2,3,4,5,1,2,3]

methodswith(typeof(a)) produces a list of methods that apply to a. But in this case you need the supertypes = true option (because most methods are defined on AbstractArray not on Array.

I doubt that the output is useful for types with many methods (1,800 in this case).

Code completion already works in the REPL. Start typing issor then hit tab and it completes to issorted, for example.

3 Likes
julia> a = Any[1, 2, 3]
3-element Vector{Any}:
 1
 2
 3

julia> push!(a, [4, 5, 6])
4-element Vector{Any}:
 1
 2
 3
  [4, 5, 6]
2 Likes

You cannot do this because:

julia> typeof([1, 2, 3])
Array{Int64,1}

So, [1, 2, 3] is a Vector that can be only used for Int64 elements. If you want to have a Vector that allows both for Ints and Vector{Int64}s as elements, then you need to declare it as Union{Int64,Vector{Int64}}[1, 2, 3]. If you want the Vector to allow any type of elements you can do Any[1, 2, 3]. If you do not specify a type before the [elem1, elem2, ...], then Julia will choose a valid element type for you. For example, if you already had Int64s and Vectors in the literal:

julia> typeof([1, 2, 3, [10, 20, 30]])
Array{Any,1}
3 Likes

Thank you hendri54 :slight_smile: .

This solves problem of finding methods of them, although i wanted a different way.

But It is not interactive. Like those in other languages
a. and tab gives alot of possible methods interactively but I didnt got , I wanted to get interactively find a way in julia.

I am thinking how julia is thinking to make it interactively to find methods, also without going to type typeof to every variables, like other languages does.

Yes I use tab if forgot some methods but it is arbitary to every and difficult to remember every classes methods .

but although this is ok for other peoples. :slight_smile:

Thank you Henrique and @jiapeyre. This solves my first problem.
In order to have [1, 2, 3, 4, 5, [1,2,3]] we have to convert array to vector and we’ll get solved.
It would be great julia would do it automatically knowing these vectors and arrays dynamically without degrading performance.

Vector is just an alias for unidimensional Array, i.e., Vectors are Array objects (Array{T, 1} more specifically). I am worried that maybe you did not understand my explanation.

1 Like

Hi I’ve understand it, nothing to worry :slight_smile: I may be able to understand after some uses.
I had thought we could use datatypes dynamically but little bit disappointed by these , but although this is ok, i may be ok .