Refactoring.jl

Refactoring tools for Julia language
Author jonathanBieler
Popularity
5 Stars
Updated Last
1 Year Ago
Started In
September 2019

Refactoring.jl

Build Status Coverage Status

Extract method

using Refactoring

m = extract_method("
    y = [sin(2xi + exp(-c)) for xi in x]
")

julia> print(m)
function (c, x)
    y = [sin(2xi + exp(-c)) for xi in x]
end

The arguments of the method are guessed by listing the variables that are unassigned in the expression:

ex = quote
    using Gadfly
    mu = K1
    const alpha = 1
    const beta = (alpha+1)*mu
    for i=1:10
        x = rand(100, f(K2)) 
    end
    plot(x = K3, y = pdf(InverseGamma(K4,beta),K5), Geom.line)
    ind, K7 = K6.asd
    x = [K8[K7] for i=1:K6]
end

julia> unassigned_variables(ex)
7-element Array{Any,1}:
 :K1
 :K2
 :K3
 :K4
 :K5
 :K6
 :K8

Search and replace

Replace all sub-expressions matching a pattern with another :

julia> @search_and_replace sin(sin(x)) sin($x) cos($x +1)
:(cos(cos(x + 1) + 1))

Used By Packages

No packages found.