This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Scala REPL with a nice html GUI

11 replies
Tiark Rompf
Joined: 2009-02-18,
User offline. Last seen 42 years 45 weeks ago.
Hi all, 
I've just put one of my little weekend projects on github (http://github.com/TiarkRompf/replhtml).
From the readme:

This project contains a Scala REPL with a GUI inspired by Mathematica worksheets. Commands can be edited and deleted, and new commands can be inserted anywhere. Whole worksheets can be re-evaluated with one click. Sessions can be saved and restored.


cheers,- Tiark
Randall R Schulz
Joined: 2008-12-16,
User offline. Last seen 1 year 29 weeks ago.
Re: Scala REPL with a nice html GUI

On Thursday October 7 2010, Tiark Rompf wrote:
> Hi all,
>
> I've just put one of my little weekend projects on github
> (http://github.com/TiarkRompf/replhtml).
>
> From the readme:
> > This project contains a Scala REPL with a GUI inspired by
> > Mathematica worksheets. Commands can be edited and deleted, and new
> > commands can be inserted anywhere. Whole worksheets can be
> > re-evaluated with one click. Sessions can be saved and restored.

Reminds me of MPW, the now long-defunct Macintosh Programmer's Workshop.
It had many virtues, including the worksheet model.

Thanks!

> cheers,
> - Tiark

Randall Schulz

Tiark Rompf
Joined: 2009-02-18,
User offline. Last seen 42 years 45 weeks ago.
Re: Scala REPL with a nice html GUI

On Oct 7, 2010, at 3:29 PM, Randall R Schulz wrote:

> On Thursday October 7 2010, Tiark Rompf wrote:
>> Hi all,
>>
>> I've just put one of my little weekend projects on github
>> (http://github.com/TiarkRompf/replhtml).
>>
>> From the readme:
>>> This project contains a Scala REPL with a GUI inspired by
>>> Mathematica worksheets. Commands can be edited and deleted, and new
>>> commands can be inserted anywhere. Whole worksheets can be
>>> re-evaluated with one click. Sessions can be saved and restored.
>
> Reminds me of MPW, the now long-defunct Macintosh Programmer's Workshop.
> It had many virtues, including the worksheet model.

Those were the days! And MPW scripts had those funny ∂ symbols all over the place. The UI is slightly different though. MPW worksheets were free-form text documents, much like nowadays, where you can execute selected text in a TextMate file. Mathematica worksheets are not completely free-form, but separated into commands, with input and output boxes. If you delete or re-evaluate a command, it will remove the previous output so text is not piling up endlessly.

cheers,
- Tiark

Ittay Dror 2
Joined: 2010-05-05,
User offline. Last seen 42 years 45 weeks ago.
Re: Scala REPL with a nice html GUI
You forgot to mention it only works in Chrome (websockets required). When I load it in other browsers (IE, FF), no error message is displayed, but nothing works either

Ittay

Tiark Rompf wrote:
41232A26-6AF9-4199-8BC3-CF996D3CF902 [at] epfl [dot] ch" type="cite">Hi all, 
I've just put one of my little weekend projects on github (http://github.com/TiarkRompf/replhtml).
From the readme:

This project contains a Scala REPL with a GUI inspired by Mathematica worksheets. Commands can be edited and deleted, and new commands can be inserted anywhere. Whole worksheets can be re-evaluated with one click. Sessions can be saved and restored.


cheers, - Tiark
Tiark Rompf
Joined: 2009-02-18,
User offline. Last seen 42 years 45 weeks ago.
Re: Scala REPL with a nice html GUI
Thanks for the comments. Yes, it uses web sockets (that's mentioned in the readme) and html 5 local storage. Safari ist your best bet to get it working. It is a proof of concept, not a release quality product. Contributions are welcome, though :-)- Tiark
On Oct 7, 2010, at 6:09 PM, Ittay Dror wrote:
You forgot to mention it only works in Chrome (websockets required). When I load it in other browsers (IE, FF), no error message is displayed, but nothing works either

Ittay

Tiark Rompf wrote:
41232A26-6AF9-4199-8BC3-CF996D3CF902 [at] epfl [dot] ch" type="cite">Hi all, 
I've just put one of my little weekend projects on github (http://github.com/TiarkRompf/replhtml).
From the readme:

This project contains a Scala REPL with a GUI inspired by Mathematica worksheets. Commands can be edited and deleted, and new commands can be inserted anywhere. Whole worksheets can be re-evaluated with one click. Sessions can be saved and restored.


cheers, - Tiark

nilskp
Joined: 2009-01-30,
User offline. Last seen 1 year 27 weeks ago.
Re: Scala REPL with a nice html GUI
On Thu, Oct 7, 2010 at 11:09 AM, Ittay Dror <ittay [dot] dror [at] gmail [dot] com> wrote:
You forgot to mention it only works in Chrome (websockets required). When I load it in other browsers (IE, FF), no error message is displayed, but nothing works either

I'm using WebSockets on FF4beta

Dean Wampler
Joined: 2008-12-26,
User offline. Last seen 42 years 45 weeks ago.
Re: Scala REPL with a nice html GUI
This is pretty nice! 
I had one odd failure. Following the readme, I ran update, compile, and run using separate sbt commands. That worked fine. However, when I tried to use all of them in one interactive sbt session, I got this error:
<script>:3: error: value replhtml is not a member of package ch.epfl.lamp  var value: ch.epfl.lamp.replhtml.ReplServlet = _                          ^<script>:4: error: value replhtml is not a member of package ch.epfl.lamp   def set(x: Any) = value = x.asInstanceOf[ch.epfl.lamp.replhtml.ReplServlet]                                                        ^java.util.NoSuchElementException: None.get        at scala.None$.get(Option.scala:185)         at scala.None$.get(Option.scala:183)        at scala.tools.nsc.Interpreter.bind(Interpreter.scala:622)        at ch.epfl.lamp.replhtml.ReplServlet$$anon$2.unleash(ReplServlet.scala:28)         at ch.epfl.lamp.replhtml.ReplServlet.<init>(ReplServlet.scala:30)        at ch.epfl.lamp.replhtml.ReplMain$.main(ReplMain.scala:17)        at ch.epfl.lamp.replhtml.ReplMain.main(ReplMain.scala)         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)         at java.lang.reflect.Method.invoke(Method.java:597)        at sbt.Run.run0(Run.scala:60)        at sbt.Run.execute$1(Run.scala:47)        at sbt.Run$$anonfun$run$2.apply(Run.scala:50)         at sbt.Run$$anonfun$run$2.apply(Run.scala:50)        at sbt.TrapExit$.executeMain$1(TrapExit.scala:33)        at sbt.TrapExit$$anon$1.run(TrapExit.scala:42)[info] == run == [error] Error running run: Nonzero exit code: 1
I'm not sure why that would matter. Again, it works fine if you follow the README instructions to the letter.
dean
On Thu, Oct 7, 2010 at 8:20 AM, Tiark Rompf <tiark [dot] rompf [at] epfl [dot] ch> wrote:
Hi all, 
I've just put one of my little weekend projects on github (http://github.com/TiarkRompf/replhtml).
From the readme:

This project contains a Scala REPL with a GUI inspired by Mathematica worksheets. Commands can be edited and deleted, and new commands can be inserted anywhere. Whole worksheets can be re-evaluated with one click. Sessions can be saved and restored.


cheers,- Tiark



Pedro Furlanetto
Joined: 2009-08-19,
User offline. Last seen 2 years 34 weeks ago.
Re: Scala REPL with a nice html GUI

Same here!

On Thu, Oct 7, 2010 at 7:10 PM, Dean Wampler wrote:
> This is pretty nice!
> I had one odd failure. Following the readme, I ran update, compile, and run
> using separate sbt commands. That worked fine. However, when I tried to use
> all of them in one interactive sbt session, I got this error:
> :3: error: value replhtml is not a member of package ch.epfl.lamp
>   var value: ch.epfl.lamp.replhtml.ReplServlet = _
>                           ^
> :4: error: value replhtml is not a member of package ch.epfl.lamp
>   def set(x: Any) = value =
> x.asInstanceOf[ch.epfl.lamp.replhtml.ReplServlet]
>                                                         ^
> java.util.NoSuchElementException: None.get
>         at scala.None$.get(Option.scala:185)
>         at scala.None$.get(Option.scala:183)
>         at scala.tools.nsc.Interpreter.bind(Interpreter.scala:622)
>         at
> ch.epfl.lamp.replhtml.ReplServlet$$anon$2.unleash(ReplServlet.scala:28)
>         at ch.epfl.lamp.replhtml.ReplServlet.(ReplServlet.scala:30)
>         at ch.epfl.lamp.replhtml.ReplMain$.main(ReplMain.scala:17)
>         at ch.epfl.lamp.replhtml.ReplMain.main(ReplMain.scala)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:597)
>         at sbt.Run.run0(Run.scala:60)
>         at sbt.Run.execute$1(Run.scala:47)
>         at sbt.Run$$anonfun$run$2.apply(Run.scala:50)
>         at sbt.Run$$anonfun$run$2.apply(Run.scala:50)
>         at sbt.TrapExit$.executeMain$1(TrapExit.scala:33)
>         at sbt.TrapExit$$anon$1.run(TrapExit.scala:42)
> [info] == run ==
> [error] Error running run: Nonzero exit code: 1
> I'm not sure why that would matter. Again, it works fine if you follow the
> README instructions to the letter.
> dean
> On Thu, Oct 7, 2010 at 8:20 AM, Tiark Rompf wrote:
>>
>> Hi all,
>> I've just put one of my little weekend projects on github
>> (http://github.com/TiarkRompf/replhtml).
>> From the readme:
>>
>> This project contains a Scala REPL with a GUI inspired by Mathematica
>> worksheets. Commands can be edited and deleted, and new commands can be
>> inserted anywhere. Whole worksheets can be re-evaluated with one click.
>> Sessions can be saved and restored.
>>
>> cheers,
>> - Tiark
>
>
> --
> Dean Wampler
> "Programming Scala" (O'Reilly)  http://programmingscala.com
> twitter: @deanwampler, @chicagoscala
> http://polyglotprogramming.com
>
>

Johannes Rudolph 2
Joined: 2010-02-12,
User offline. Last seen 42 years 45 weeks ago.
Re: Scala REPL with a nice html GUI

That's already pretty cool. I've got something like that on my idea
list since several months, but didn't yet got to make a move.

Are there any particular reasons why you implemented that mostly on
the client side?

Thanks for making that available!

On Thu, Oct 7, 2010 at 3:20 PM, Tiark Rompf wrote:
> Hi all,
> I've just put one of my little weekend projects on github
> (http://github.com/TiarkRompf/replhtml).
> From the readme:
>
> This project contains a Scala REPL with a GUI inspired by Mathematica
> worksheets. Commands can be edited and deleted, and new commands can be
> inserted anywhere. Whole worksheets can be re-evaluated with one click.
> Sessions can be saved and restored.
>
> cheers,
> - Tiark

Tiark Rompf
Joined: 2009-02-18,
User offline. Last seen 42 years 45 weeks ago.
Re: Scala REPL with a nice html GUI

The issue with having to run sbt update and sbt run separately should be fixed now.

On Oct 8, 2010, at 10:25 AM, Johannes Rudolph wrote:

> That's already pretty cool. I've got something like that on my idea
> list since several months, but didn't yet got to make a move.

You're more than welcome to do some hacking on this one :-)

> Are there any particular reasons why you implemented that mostly on
> the client side?

Most of it is just dom manipulations. Moving the control logic to the server would
just complicate matters and add unnecessary overhead. Also, with the ui completely
implemented on the client, you can open the html file and click around even if there is
no server running. I think that is actually quite handy, for example if you want to
restart the server to reload some classes (let's assume you don't use JRebel),
then the gui remains alive and you just need to hit 'reload' and 'execAll' once the
server is back up.

cheers,
- Tiark

>
> Thanks for making that available!
>
> On Thu, Oct 7, 2010 at 3:20 PM, Tiark Rompf wrote:
>> Hi all,
>> I've just put one of my little weekend projects on github
>> (http://github.com/TiarkRompf/replhtml).
>> From the readme:
>>
>> This project contains a Scala REPL with a GUI inspired by Mathematica
>> worksheets. Commands can be edited and deleted, and new commands can be
>> inserted anywhere. Whole worksheets can be re-evaluated with one click.
>> Sessions can be saved and restored.
>>
>> cheers,
>> - Tiark
>
>
>

adriaanm
Joined: 2010-02-08,
User offline. Last seen 31 weeks 4 days ago.
Re: Scala REPL with a nice html GUI
Hey,
Awesome! Can't wait to use this for my next class! For extra visual impact, could you incorporate something like highlight.js[1] for syntax highlighting? Of course this is purely frivolous.
I did notice a few minor glitches: if you add a // comment on the first line, hit shift-enter and then copy/paste code, the first line of copy/pasted code is ignored. Also, I've sometimes needed to add a semi-colon at the end of the first line when copy/pasting code over line by line. I assume both are instances of the same bug.
thanks!adriaan
ps: [1] http://softwaremaniacs.org/soft/highlight/en/you need to download a custom pack that contains Scala, include a syntax.css, and I think you'll need to insert addition <code> tags (highlight.js seems to be hardwired that way) and tweak your webapp to call highlightCode whenever content is edited. I don't know much about JavaScript, so unfortunately can't contribute. I ended up not using highlight.js on my homepage because I couldn't figure out how to tweak it to my needs...

On Fri, Oct 8, 2010 at 3:58 PM, Tiark Rompf <tiark [dot] rompf [at] epfl [dot] ch> wrote:
The issue with having to run sbt update and sbt run separately should be fixed now.

On Oct 8, 2010, at 10:25 AM, Johannes Rudolph wrote:

> That's already pretty cool. I've got something like that on my idea
> list since several months, but didn't yet got to make a move.

You're more than welcome to do some hacking on this one :-)

> Are there any particular reasons why you implemented that mostly on
> the client side?

Most of it is just dom manipulations. Moving the control logic to the server would
just complicate matters and add unnecessary overhead. Also, with the ui completely
implemented on the client, you can open the html file and click around even if there is
no server running. I think that is actually quite handy, for example if you want to
restart the server to reload some classes (let's assume you don't use JRebel),
then the gui remains alive and you just need to hit 'reload' and 'execAll' once the
server is back up.

cheers,
- Tiark

>
> Thanks for making that available!
>
> On Thu, Oct 7, 2010 at 3:20 PM, Tiark Rompf <tiark [dot] rompf [at] epfl [dot] ch> wrote:
>> Hi all,
>> I've just put one of my little weekend projects on github
>> (http://github.com/TiarkRompf/replhtml).
>> From the readme:
>>
>> This project contains a Scala REPL with a GUI inspired by Mathematica
>> worksheets. Commands can be edited and deleted, and new commands can be
>> inserted anywhere. Whole worksheets can be re-evaluated with one click.
>> Sessions can be saved and restored.
>>
>> cheers,
>> - Tiark
>
>
>
> --
> Johannes
>
> -----------------------------------------------
> Johannes Rudolph
> http://virtual-void.net


Tiark Rompf
Joined: 2009-02-18,
User offline. Last seen 42 years 45 weeks ago.
Re: Scala REPL with a nice html GUI
Awesome! Can't wait to use this for my next class! For extra visual impact, could you incorporate something like highlight.js[1] for syntax highlighting? Of course this is purely frivolous.

That would certainly be nice, but it is a little tricky to make it work with editable text. Highlight.js will replace plain text dom nodes with div and span nodes, which means (for example) that you will lose any current selection/insertion point. When you are typing that's not what you want. It can be done (by saving and restoring the selection) but it's a bit of work.

I did notice a few minor glitches: if you add a // comment on the first line, hit shift-enter and then copy/paste code, the first line of copy/pasted code is ignored. Also, I've sometimes needed to add a semi-colon at the end of the first line when copy/pasting code over line by line. I assume both are instances of the same bug.

Hitting just enter after a single // line will not work because the interpreter says the line contains an error:
scala> repl.interpret("// comment")res25: scala.tools.nsc.InterpreterResults.Result = Error
Shift-enter and copy/paste should work now.
- Tiark
ps: [1] http://softwaremaniacs.org/soft/highlight/en/you need to download a custom pack that contains Scala, include a syntax.css, and I think you'll need to insert addition <code> tags (highlight.js seems to be hardwired that way) and tweak your webapp to call highlightCode whenever content is edited. I don't know much about JavaScript, so unfortunately can't contribute. I ended up not using highlight.js on my homepage because I couldn't figure out how to tweak it to my needs...

On Fri, Oct 8, 2010 at 3:58 PM, Tiark Rompf <tiark [dot] rompf [at] epfl [dot] ch> wrote:
The issue with having to run sbt update and sbt run separately should be fixed now.

On Oct 8, 2010, at 10:25 AM, Johannes Rudolph wrote:

> That's already pretty cool. I've got something like that on my idea
> list since several months, but didn't yet got to make a move.

You're more than welcome to do some hacking on this one :-)

> Are there any particular reasons why you implemented that mostly on
> the client side?

Most of it is just dom manipulations. Moving the control logic to the server would
just complicate matters and add unnecessary overhead. Also, with the ui completely
implemented on the client, you can open the html file and click around even if there is
no server running. I think that is actually quite handy, for example if you want to
restart the server to reload some classes (let's assume you don't use JRebel),
then the gui remains alive and you just need to hit 'reload' and 'execAll' once the
server is back up.

cheers,
- Tiark

>
> Thanks for making that available!
>
> On Thu, Oct 7, 2010 at 3:20 PM, Tiark Rompf <tiark [dot] rompf [at] epfl [dot] ch> wrote:
>> Hi all,
>> I've just put one of my little weekend projects on github
>> (http://github.com/TiarkRompf/replhtml).
>> From the readme:
>>
>> This project contains a Scala REPL with a GUI inspired by Mathematica
>> worksheets. Commands can be edited and deleted, and new commands can be
>> inserted anywhere. Whole worksheets can be re-evaluated with one click.
>> Sessions can be saved and restored.
>>
>> cheers,
>> - Tiark
>
>
>
> --
> Johannes
>
> -----------------------------------------------
> Johannes Rudolph
> http://virtual-void.net



Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland