

Ask HN: programming languages written in JavaScript? - Tichy

I think it would be a good idea if web sites started embedding Greasemonkey into their sites, that is, to allow users to customize their site (or host user's scripts). The problem is that if one just uses JavaScript, one can't limit the access options. Therefore I think another language is needed that is being interpreted by Javascript.<p>For that new language, the host would habe better control on the kinds of API to allow. For example, rather than allowing general HTTP requests to the site, only certain parts of the site's API could be exposed.<p>So I wonder what languages there already are that run on top of JavaScript.
======
lethain
Look into Caja <http://code.google.com/p/google-caja/> it lets you safely
imbed third party JavaScript into your pages.

------
llimllib
Strands is a language written in JS; the language is javascript itself except
with concurrency primitives added: <http://www.xucia.com/strands-
doc/index.html>

I mention strands to say that you could do something similar: by using
narcissus (a js interptreter written in js -
<http://mxr.mozilla.org/mozilla/source/js/narcissus/>) you could interpret a
language that was a subset of javascript, with whatever restrictions you
wanted. Though javascript's extremely dynamic nature would possibly make this
challenging.

More pragmatically, lethain's right that you should look into caja.

------
wheels
Objective-J is a Objective-C-like language interpreted by JS from a YC
startup:

<http://cappuccino.org/learn/>

No idea if it's possible to do what you're hoping for though, just glanced at
the API a while back.

------
streety
As a website user what's the benefit to me? Why would I invest time and effort
in learning a new language just so I can play with the emaciated relative of
javascript?

I can envision situations where additional functionality could be created by
site developers but it would be as accessible to greasemonkey scripts as it
would be to a language built on top of javascript.

What specific situations do you think this would be useful?

~~~
Tichy
Not so keen on the new language myself - OK then, maybe a Javascript emulator
in Javascript is called for.

The benefit: the same benefit that other open source software has. If I am
unsatisfied with a particular behaviour of the application, I can change it.

Of course people could just use Greasemonkey, but I think if a web site
endorses the thing, it might reach more users. Greasemonkey also requires the
installation of a plugin, which severely limits it's usability.

Also, perhaps one could offer better features for discovering scripts and
judging their safety than what is currently on offer with Greasemonkey.

~~~
streety
You are right there would be advantages for anyone using a browser that is
locked down. I guess it has been too long since I was in that position.

~~~
Tichy
Meanwhile I realised that probably one could just overload all offending
objects (like XMLHttpRequest), JavaScript being a dynamic language.

Another target audience would be the mobile phone browsers, don't think they
are enabled for plugins yet.

------
Kaizyn
There's always OMeta: <http://www.cs.ucla.edu/~awarth/ometa/>

This is a generalized tool that will let you specify any language you want and
target Javascript. OMeta has been implemented in several different languages;
the Javascript implementation is just a couple hundred lines of code.

------
mindaugas
I'm not really sure but maybe ... processing.js ?
<http://ejohn.org/blog/processingjs/>

I think it can serve as an example.

~~~
nostrademons
If you count Processing.js, there's also ArcLite:

<http://jonathan.tang.name/code/arclite>

Processing.js may not be the best example for new language implementers,
because the compiler is implemented with regexp search & replace. That makes
it fairly fast, but difficult to extend and almost impossible for a neophyte
to read.

------
cabalamat
Papert is a Logo interpreter written in JavaScript --
<http://logo.twentygototen.org/>

