Some Julia support

129 views
Skip to first unread message

William Stein

unread,
Oct 26, 2014, 2:59:29 PM10/26/14
to sage-cloud
Hi SageMathCloud Enthusiasts,

SageMathCloud worksheets now have a new %julia mode to support the
Julia programming language. Here's a demo worksheet (to use it in
your own project, make sure to restart your project server first to
get the ~/.sagemathcloud/julia.py file):

https://cloud.sagemath.com/projects/4a5f0542-5873-4eed-a85c-a18c706e8bcd/files/julia/julia-tutorial.sagews

--
William Stein
Professor of Mathematics
University of Washington
http://wstein.org
Screen Shot 2014-10-26 at 11.52.49 AM.png

c.d. mclean

unread,
Oct 27, 2014, 12:42:55 AM10/27/14
to sage-...@googlegroups.com

brilliant, William !!!

thank you very much
for all of your efforts.

i look forward to giving
this a whirl ...

best,

cdm

William Stein

unread,
Oct 27, 2014, 12:48:42 AM10/27/14
to sage-cloud
Cool. Please don't hesitate to give me feedback, report issues, etc.
I don't know Julia very well yet, so I wasn't sure what sort of subtle
things might go wrong.

> best,
>
> cdm
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-cloud" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-cloud+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sage-cloud/8c66f9f4-9cf5-4172-8ce7-5c1f0bb1ea6e%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

c.d. mclean

unread,
Oct 27, 2014, 4:54:04 PM10/27/14
to sage-...@googlegroups.com

the help in the Sage worksheet references the capability to enter the Python help from the Sage worksheet
using "python_help()" ...

does it make sense to add the Julia analog to this?

the Julia help is currently accessible via:

%julia
help()

certainly, the current status is sufficient.

best,

cdm
 

Pablo Zubieta

unread,
Oct 28, 2014, 4:37:30 PM10/28/14
to sage-...@googlegroups.com
This is great!

I was looking at the demo and noticed that in order to restart julia, you ran

%sage
julia
.quit()

In the julia REPL and IJulia, workspace() is used to do replace the top-level module (Main) with a new one, providing a clean workspace. I tried in a sagews and it works but it prints out something ugly.

the function workspace is defined in julia as

function workspace()
   
last = Core.Main
    b
= last.Base
    ccall
(:jl_new_main_module, Any, ())
    m
= Core.Main
    ccall
(:jl_add_standard_imports, Void, (Any,), m)
   
eval(m,
         
Expr(:toplevel,
             
:(const Base = $(Expr(:quote, b))),
             
:(const LastMain = $(Expr(:quote, last)))))
    empty
!(package_list)
    empty
!(package_locks)
    nothing
end

I'm not sure where the printed output comes from, but it might be possible to find a solution writing a similar function in the .juliarc.jl file fo it gets defined everytime julia starts.

William Stein

unread,
Oct 28, 2014, 4:49:01 PM10/28/14
to sage-cloud
On Tue, Oct 28, 2014 at 1:37 PM, Pablo Zubieta <pabl...@gmail.com> wrote:
> This is great!
>
> I was looking at the demo and noticed that in order to restart julia, you
> ran
>
> %sage
> julia.quit()
>
> In the julia REPL and IJulia, workspace() is used to do replace the
> top-level module (Main) with a new one, providing a clean workspace. I tried
> in a sagews and it works but it prints out something ugly.
>
> the function workspace is defined in julia as
>
> function workspace()
> last = Core.Main
> b = last.Base
> ccall(:jl_new_main_module, Any, ())
> m = Core.Main
> ccall(:jl_add_standard_imports, Void, (Any,), m)
> eval(m,
> Expr(:toplevel,
> :(const Base = $(Expr(:quote, b))),
> :(const LastMain = $(Expr(:quote, last)))))
> empty!(package_list)
> empty!(package_locks)
> nothing
> end

Thanks. All that "ugly stuff" that gets printed out must be the
result of the synchronization code getting interrupted halfway through
due to running workspace(), which presumably stops it. I'll fix
things so that workspace() doesn't output that. Thanks for letting me
know about it.

Any other thoughts/comments/issues?

William

c.d. mclean

unread,
Oct 28, 2014, 4:51:47 PM10/28/14
to sage-...@googlegroups.com

code completion was not working
for me yesterday ... but, today it
is on.

really impressive work, William.

well done !!!

cdm

c.d. mclean

unread,
Oct 28, 2014, 4:58:26 PM10/28/14
to sage-...@googlegroups.com

on the code complete, i notice
that the selection list is not
always ordered alphabetically ...

i imagine that there must be
some other collection source
driving the order, not critical
(i found the function i was
looking for on the list ...),
but one of those things that
gets noticed.

best,

cdm

William Stein

unread,
Oct 28, 2014, 5:03:36 PM10/28/14
to sage-cloud
On Tue, Oct 28, 2014 at 1:58 PM, c.d. mclean <cdmcle...@gmail.com> wrote:
>
> on the code complete, i notice
> that the selection list is not
> always ordered alphabetically ...

Can you give me an example of what sort of completions you're
expecting to use and how it should work? I actually don't think I
implemented any intelligent completions, except maybe "control+space",
which is just some trivial thing. For full tab completion to work, I
would have to learn what functions one calls in Julia to do
introspection, and what sort of output is expected. Please tell me
what you can...

>
> i imagine that there must be
> some other collection source
> driving the order, not critical
> (i found the function i was
> looking for on the list ...),
> but one of those things that
> gets noticed.
>
> best,
>
> cdm
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-cloud" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-cloud+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sage-cloud/813449d2-623d-4ca5-9102-761a73875f11%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



William Stein

unread,
Oct 28, 2014, 5:28:22 PM10/28/14
to sage-cloud
Hi,

I fixed the synchronization, so

%julia
workspace()

should now work fine, in addition to some other things that didn't
quite work right involving parsing, possibly. Project server restart
required.

William Stein

unread,
Oct 28, 2014, 5:34:09 PM10/28/14
to sage-cloud
For completions, I suspect you want behavior just like this:

http://julia.readthedocs.org/en/latest/manual/interacting-with-julia/#tab-completion

It's pretty interesting and subtle! "The tab key can also be used to
substitute LaTeX math symbols with their Unicode equivalents, and get
a list of LaTeX matches as well:"

-- William

Pablo Zubieta

unread,
Oct 28, 2014, 5:56:34 PM10/28/14
to sage-...@googlegroups.com
Thanks for the fixes!

For the completion is would be really nice to have the same one as in the existing interactive implementations of julia (the same one you are referring to). I love that feature and I'm sure other wil find it pretty neat too.

Pablo

William Stein

unread,
Oct 28, 2014, 6:15:18 PM10/28/14
to sage-cloud


On Oct 28, 2014 2:57 PM, "Pablo Zubieta" <pabl...@gmail.com> wrote:
>
> Thanks for the fixes!
>
> For the completion is would be really nice to have the same one as in the existing interactive implementations of julia (the same one you are referring to). I love that feature and I'm sure other wil find it pretty neat too.
>

I'll aim for that.  With pexpect (which I'm using) I can literally send a tab and read the results....

> Pablo


>
> --
> You received this message because you are subscribed to the Google Groups "sage-cloud" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-cloud+...@googlegroups.com.

> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-cloud/a0195565-55b3-4d52-9938-8fa6b3773ec8%40googlegroups.com.

William Stein

unread,
Oct 30, 2014, 12:16:00 AM10/30/14
to sage-cloud
On Tue, Oct 28, 2014 at 3:15 PM, William Stein <wst...@gmail.com> wrote:
>
> On Oct 28, 2014 2:57 PM, "Pablo Zubieta" <pabl...@gmail.com> wrote:
>>
>> Thanks for the fixes!
>>
>> For the completion is would be really nice to have the same one as in the
>> existing interactive implementations of julia (the same one you are
>> referring to). I love that feature and I'm sure other wil find it pretty
>> neat too.
>>

I've made one small step in this direction just now. It's the
foundation needed to build something better.

If you type

julia.<something>[tab]

then you'll see the completions of <something>, as if you typed that
on the command line. Also, you can do

x = julia(<stuff>)
x.<something>[tab]

For this to work, restart your project server.

To make this more useful, obviously I need to:

(1) make it so if the current cell starts with %julia and you type
<something>tab, then you get completions for julia.<something>. (More
generally, I need to do this for all % modes.)

(2) make it so that if the default mode is julia, then typing
<something>tab anywhere gives the completions.

(3) while I'm at it, make it so the if the default mode is julia
(etc.), then the editor mode defaults to julia, for proper syntax
highlighting, autoindent, code folding, etc. (Instead of having to
type %julia.)

But anyway, at least julia.stuff [tab] works now, which is a useful step.

-- William




>
> I'll aim for that. With pexpect (which I'm using) I can literally send a
> tab and read the results....
>
>> Pablo
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "sage-cloud" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to sage-cloud+...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/sage-cloud/a0195565-55b3-4d52-9938-8fa6b3773ec8%40googlegroups.com.
>>
>> For more options, visit https://groups.google.com/d/optout.



Screen Shot 2014-10-29 at 9.05.08 PM.png

c.d. mclean

unread,
Oct 30, 2014, 5:46:17 PM10/30/14
to sage-...@googlegroups.com

On Wednesday, October 29, 2014 9:16:00 PM UTC-7, William Stein wrote:
But anyway, at least julia.stuff [tab] works now, which is a useful step.

agreed. that step is quite useful; thank you.

i will do some searching of the forum, but are
any of the accessible remote machines running
with ARM processors; if not is this a possibility?

if so i may attempt to tinker with unresolved issues
of getting Julia running on ARM cpu systems ...

many thanks,

cdm

William Stein

unread,
Oct 30, 2014, 5:49:10 PM10/30/14
to sage-cloud
I personally don't have access to any online computers with ARM cpu's
at present...

>
> many thanks,
>
> cdm
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-cloud" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-cloud+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sage-cloud/e2ae26c0-e5a0-41b4-8192-46ab0b2eb9c9%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages