gjkerns / ob-julia

36 stars 25 forks source link

Julia function definition in code block #1

Closed bosmacs closed 10 years ago

bosmacs commented 10 years ago

First, many thanks for creating ob-julia. Is it possible to have just a julia function definition in a code block, to be called later in a separate block? I get the following error from executing a code block containing only a function definition:

ERROR: no method start(Function)
 in writedlm at datafmt.jl:534
 in anonymous at datafmt.jl:549
 in open at io.jl:373
 in writedlm at datafmt.jl:548
 in writecsv at datafmt.jl:554
 in _start at ./client.jl:393

If I add a call to the function as the last line in the block, it evaluates successfully and outputs the results block. I'm running juila 0.3.0-prerelease+3921. Any suggestions?

gjkerns commented 10 years ago

Interesting. I am running Julia 0.2.0 and both of the following seem to be working for me, whether I evaluate the function or not:

+BEGIN_SRC julia

f(x,y) = x + y

+END_SRC

and

+BEGIN_SRC julia

function f(x,y) x + y end

+END_SRC

That would suggest that, whatever the problem is, it is either with some change introduced to julia after 0.2.0, or maybe there's something spooky about your function that is triggering a problem not caught by my toy example.

I haven't updated to julia 0.3.0 because I haven't yet managed to get my gentoo ebuild to compile without error. If you find out that the problem is associated with the newer julia, then please let me know and I'll see if I can get my julia updated and try to track this problem down.

Thanks for the report.

bosmacs commented 10 years ago

I'm guessing it's a 0.3 issue; I have the same problem with your examples above. Furthermore, it's not limited to function definitions -- I tried this example from the documentation:

#+BEGIN_SRC julia
using Winston
x = linspace(0, 3pi, 100)
c = cos(x)
s = sin(x)
p = FramedPlot();
setattr(p, "title", "title!")
setattr(p, "xlabel", L"\Sigma x^2_i")
setattr(p, "ylabel", L"\Theta_i")
add(p, FillBetween(x, c, x, s) )
add(p, Curve(x, c, "color", "red") )
add(p, Curve(x, s, "color", "blue") )
#+END_SRC

which results in a similar error:

ERROR: no method start(FramedPlot)
 in writedlm at datafmt.jl:534
 in anonymous at datafmt.jl:549
 in open at io.jl:373
 in writedlm at datafmt.jl:548
 in writecsv at datafmt.jl:554
 in _start at ./client.jl:393

On the other hand, this example does work:

#+BEGIN_SRC julia
rand(2,3)
#+END_SRC

#+RESULTS:
| 0.2448279259747248 |  0.716611209557517 | 0.1870315257952695 |
| 0.2085936609008061 | 0.4714950737687482 | 0.7900168300666228 |

I don't know if it's related, but it appears that Julia 0.3 no longer includes a separate julia-release-basic executable, so I set inferior-julia-program-name to point to the julia executable, which seems to work OK for an ESS julia session at least. If I have time today I'll try the 0.2 release to verify that this is a 0.3 issue.

bosmacs commented 10 years ago

Well, I confirmed that it does work for me with the julia 0.2.1 release. On top of that, it's now working after switching back to 0.3. Sorry about the false alarm; it's obviously something on my end...