code location in eval (ESS/julia)

159 views
Skip to first unread message

Tamas Papp

unread,
Feb 18, 2015, 8:16:02 AM2/18/15
to juli...@googlegroups.com
Hi,

I experimenting with some extensions to Julia in ESS: in particular, I
would like code sent to the Julia inferior process to be aware of the
module and the location. Mike Innes on julia-users already told me that
I can use

eval(module, :(code))

for the module, but how can I make Julia aware of the line numbers? Eg
if I am in file PATH, and evaluating the code between bytes/characters
START and END, what would I send to the Julia process?

(If this is already in Jewel.jl, please just point out what to use).

Best,

Tamas

Mike Innes

unread,
Feb 18, 2015, 9:05:04 AM2/18/15
to juli...@googlegroups.com
Jewel.jl extends include_string with a couple of extra methods that will be useful to you:

include_string(code, file, line)
include_string(module, code, file, line)

They should be fairly self-explanatory but let me know if you run into any issues.

Tamas Papp

unread,
Feb 24, 2015, 9:28:07 AM2/24/15
to juli...@googlegroups.com
A question: given a module name as a _string_,

1. how can I look up the module _object_ to pass to include_string?

2. what would be a sensible way to recover if the module does not exist
yet? Eg the user just opened a file

--8<---------------cut here---------------start------------->8---
module Foo

function bar() = 42

end
--8<---------------cut here---------------end--------------->8---

and evaluated the middle line. Should the interface just quietly define
the module? Or maybe define it, but with a warning?

Best,

Tamas

mike.j...@gmail.com

unread,
Feb 25, 2015, 3:17:56 PM2/25/15
to juli...@googlegroups.com
Ok, so Jewel.jl also gives you a function called `getthing`, the signature of which is essentially:

getthing([module = Main], “Foo.bar”, [default = nothing])

i.e. it will pull out some arbitrarily nested/qualified object from a given module (`Main`, by default) or return `nothing` if it can’t find it. That’s a really useful tool for pulling things out of text.

For (2), there are basically two options: (a), define the module with a warning, or (b) throw an error. I’m not sure what the best choice there is so you’d probably just have to try both out and see which one is more annoying in practice.

(Now I think about it, I’m not sure Jewel.jl does either – in fact I think it just silently evals into `Main`, which isn’t the right way to go at all)
Reply all
Reply to author
Forward
0 new messages