---
layout: post
title: Resurgange of the shell.
tags:
- Mono
- JavaScript
created: 1221119856
---
Two things happened in such short proximity time-wise that I can't help but thing they're somehow related to the larger shift to interpreters. Earlier this week Miguel introduced csharp shell which forced me to dust off my shoddy Mono 1.9 build and rebuild Mono from Subversion just because this is too interesting to pass up on.
Time Service Department, US Naval Observatory
One of my favorite aspects of using IronPyhton, or Python for that matter is the interpreter which allows for prototyping that doesn't involve creating little test apps that I have to build to prove a point. For example, I can work through fetching a web page in the csharp shell really easily, instead of creating a silly little application, compiling, fixing errors, and recompiling:
tyler@pineapple:~/source/mono-project/mono> csharp
Mono C# Shell, type "help;" for help
Enter statements below.
csharp> using System;
csharp> Console.WriteLine("This changes everything.");
This changes everything.
csharp> String url = "http://tycho.usno.navy.mil/cgi-bin/timer.pl";
csharp> using System.Web;
csharp> using System.Net;
csharp> using System.IO;
csharp> using System.Text;
csharp> HttpWebRequest req = HttpWebRequest.Create(url);
csharp> HttpWebRequest req = HttpWebRequest.Create(url) as HttpWebRequest;
csharp> HttpWebResponse response = req.GetResponse() as HttpWebResponse;
csharp> StreamReader reader = new StreamReader(req.GetResponseStream() as Stream, Encoding.UTF8);
csharp> StreamReader reader = new StreamReader(response.GetResponseStream() as Stream, Encoding.UTF8);
csharp> String result = reader.ReadToEnd();
csharp> Console.WriteLine(result);
US Naval Observatory Master Clock Time
Sep. 11, 07:29:02 UTC
Sep. 11, 03:29:02 AM EDT
Sep. 11, 02:29:02 AM CDT
Sep. 11, 01:29:02 AM MDT
Sep. 11, 12:29:02 AM PDT
Sep. 10, 11:29:02 PM AKDT
Sep. 10, 09:29:02 PM HAST
csharp> reader.Close();
csharp> response.Close();
csharp>
I really think Miguel and Co. have adding something infinitely more useful in this Hackweek project than anything I've seen come out of recent hackweeks at Novell. The only feature request that I'd add along to the csharp shell would be "recording", i.e.:
Which could conceptually generate the following file:
tyler@pineapple:~/source/mono-project/mono> csharp
Mono C# Shell, type "help;" for help
Enter statements below.
csharp> Shell.record("public void Main(string[] args)");
recording...
csharp> using System;
csharp> Console.WriteLien("I prototyped this in csharp shell!");
/home/tyler/basket/lib/mono/2.0/mscorlib.dll (Location of the symbol related to previous error)
csharp> Console.WriteLine("I prototyped this in csharp shell!");
csharp> Shell.save_record("Hello.cs");
recording saved to "Hello.cs"
using System;
public class Hello
{
public void Main(string[] args)
{
Console.WriteLine("I prototyped this in csharp shell!");
}
}
tyler@pineapple:~/source/v8> ./shell
V8 version 0.3.0
> load("window-compat.js");
> load("jquery.js");
> $ = window.$
function (selector,context){return new jQuery.fn.init(selector,context);}
> x = [1, 5, 6, 12, 42];
1,5,6,12,42
> $.each(x, function(index) { print("x[" + index + "] = " + this); });
x[0] = 1
x[1] = 5
x[2] = 6
x[3] = 12
x[4] = 42
1,5,6,12,42
>
The contents of "window-compat.js" being:
/*
* Providing stub "window" objects for jQuery
*/
if (typeof(window) == 'undefined') {
window = new Object();
document = window;
self = window;
navigator = new Object();
navigator.userAgent = navigator.userAgent || 'Chrome v8 Shell';
location = new Object();
location.href = 'file:///dev/null';
location.protocol = 'file:';
location.host = '';
};