Skip to content
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

StringIndexError #164

Closed
jacob-roth opened this issue Mar 7, 2019 · 1 comment · Fixed by #178
Closed

StringIndexError #164

jacob-roth opened this issue Mar 7, 2019 · 1 comment · Fixed by #178

Comments

@jacob-roth
Copy link

jacob-roth commented Mar 7, 2019

I get a weird error trying to paste a function into the REPL. My code in a text editor is:

using ForwardDiff

const Y = [  20.0  -10.0  -10.0
            -10.0   20.0  -10.0
            -10.0  -10.0   20.0]
const P = [ -1.0; -2.0; 3.0]
const Q = [ -0.1; 0.0; 0.1]

function G(rθ; Y, P, Q)
    N = length(rθ); n = div(N, 2)
    r = rθ[1:n]; θ = rθ[(n+1):(N)]
    vr = r .* cos.(θ)
    vi = r .* sin.(θ)
    return vr' * Y * vr + vi' * Y * vi + P' * θ + Q' * log.(r)
end
function dG(rθ; Y, P, Q)
    g = rθ -> G(rθ, Y=Y, P=P, Q=Q)
    return ForwardDiff.gradient(g, rθ)
end
function d2G(rθ; Y, P, Q)
    g = rθ -> G(rθ, Y=Y, P=P, Q=Q)
    return ForwardDiff.hessian(g, rθ)
end
r = [1.0; 1.0; 1.0]
θ = [0.0; 0.0; 0.0]
rθ = [r; θ]
G(rθ; Y=Y, P=P, Q=Q)
dG(rθ; Y=Y, P=P, Q=Q)
d2G(rθ; Y=Y, P=P, Q=Q)

and when I paste everything in to the REPL, everything is fine except for d2G(rθ; Y=Y, P=P, Q=Q). It disappears, and I get the following error:

julia> ┌ Error: Error in the keymap
│   exception =
│    StringIndexError("d2G(rθ; Y=Y, P=P, Q=Q)", 7)
│    Stacktrace:
│     [1] string_index_err(::String, ::Int64) at ./strings/string.jl:12
│     [2] getindex(::String, ::UnitRange{Int64}) at ./strings/string.jl:248
│     [3] (::getfield(OhMyREPL.Prompt, Symbol("##25#51")))(::Any, ::Any, ::Any) at /Users/jakeroth/.julia/packages/OhMyREPL/s4GzH/src/repl.jl:190
│     [4] #invokelatest#1 at ./essentials.jl:742 [inlined]
│     [5] invokelatest at ./essentials.jl:741 [inlined]
│     [6] (::getfield(REPL.LineEdit, Symbol("##27#28")){getfield(OhMyREPL.Prompt, Symbol("##25#51")),String})(::Any, ::Any) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/REPL/src/LineEdit.jl:1324
│     [7] prompt!(::REPL.Terminals.TextTerminal, ::REPL.LineEdit.ModalInterface, ::REPL.LineEdit.MIState) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/REPL/src/LineEdit.jl:2365
│     [8] run_interface(::REPL.Terminals.TextTerminal, ::REPL.LineEdit.ModalInterface, ::REPL.LineEdit.MIState) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/REPL/src/LineEdit.jl:2268
│     [9] run_frontend(::REPL.LineEditREPL, ::REPL.REPLBackendRef) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:1035
│     [10] run_repl(::REPL.AbstractREPL, ::Any) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:192
│     [11] (::getfield(Base, Symbol("##734#736")){Bool,Bool,Bool,Bool})(::Module) at ./client.jl:362
│     [12] #invokelatest#1 at ./essentials.jl:742 [inlined]
│     [13] invokelatest at ./essentials.jl:741 [inlined]
│     [14] run_main_repl(::Bool, ::Bool, ::Bool, ::Bool, ::Bool) at ./client.jl:346
│     [15] exec_options(::Base.JLOptions) at ./client.jl:284
│     [16] _start() at ./client.jl:436
└ @ REPL.LineEdit /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/REPL/src/LineEdit.jl:2367

However, it works fine if I actually enter the function's name letter-by-letter in the REPL. I wonder what I'm messing up?

@KristofferC
Copy link
Owner

OhMyREPL.jl is messing up the string handling somewhere. Will look at it in the upcoming days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants