Funny, I've thought about that as well. And I've seen a similar project
before, translating Perl6 to JavaScript. JavaScript is a pretty nice
language, I think that implementing at least a subset of J should be very
doable.
To get the whole implementation of J without having to work very hard :
Use the XMLhttp object. You can directly call J sentence from javascript
dynamically that would run the J sentence on the server, and saves all
names and verbs in a session file. You can return a javascript variable
when you need to get a variable result.
Simple example for a single user session and the web script I've sent
yesterday :
{ javascript part }
xmlhttp=null;
if (window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest();
else if (window.ActiveXObject)
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
function RunJ (str)
{
var now = new Date();
xmlhttp.open("POST", "query.php",false);
xmlhttp.setRequestHeader
('Content-Type','application/x-www-form-urlencoded');
xmlhttp.send(str);
if (xmlhttp.status==200)
eval (xmlhttp.responseText);
}
Somewhere...
function Test ()
{
RunJ ('a =: i. 3 2');
RunJ ('b =: < a + 1');
RunJ ('display b');
}
In J you would have to add the display verb in this case to output :
display =: 3 : 0
echo 'alert ("' , ({: cut cmd) , ' = ' , (}:;LF,~ each <"1 ": y.) ,
'");'
)
The eval function in the function RunJ will run the result from J and
will display a messagebox with the content of b :
+---+
|1 2|
|3 4|
|5 6|
+---+
Best regards,
Simon
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm