RSS 2.0

Personal Info:

Joe Send mail to the author(s) leads the architecture of an experimental OS's developer platform, where he is also chief architect of its programming language. His current mission is to enable writing large-scale software that is reliable, secure, and scalable by-construction. Before this, Joe founded the Parallel Extensions to .NET project. He has been granted 19 patents, with 49 pending. When not working, Joe enjoys travelling with his wife, writing books, writing music, studying music theory & mathematics, and doing anything involving food & wine.

My books

My music

Disclaimer:
The content of this site are my own personal opinions and do not represent my employer's view in anyway.

© 2012, Joe Duffy

 
 Thursday, July 21, 2005

It seems JScript was a bit ahead of its time, in much the same sense that Lisp was. More accurately ECMAScript was, the standard on which Microsoft's implementation was based.

In 3 lines of code, here is a REPL that compiles and works. It is written in JScript.NET itself (jsc.exe):

import System;
while (true)
    print(eval(Console.ReadLine()));

A more robust version can be written in roughly 50 lines of code:

import System;
import System.Text;

function read()
{
    var program = new StringBuilder();

    while (true)
    {
        Console.Write("{0}{0} ", program.Length == 0 ? ">" : ".");
        var line = Console.ReadLine();
        if (line != "")
        {
            if (program.Length == 0 && line.StartsWith("!q"))
                break;
            else
                program.AppendLine(line);
        }
        else if (program.Length != 0)
        {
            break;
        }
    }

    return program.ToString();
}

function evalprint(program)
{
    try
    {
        var o = eval(program);
        Console.WriteLine("=> {0}", o);
    }
    catch (e)
    {
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Error.WriteLine(e.ToString());
        Console.ResetColor();
    }
}

while (true)
{
    var program = read();
    if (program == "") break;
    evalprint(program);
}

It's just a matter of time before C# and the world at large embrace the power of eval().

7/21/2005 12:26:40 AM (Pacific Daylight Time, UTC-07:00)  #   

 

Recent Entries:

Search:

Browse by Date:
<July 2005>
SunMonTueWedThuFriSat
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

Browse by Category:

Notables: