5 ms·
Clamato: A Smalltalk Dialect for Javascript
- skybrian 17y agoNeat. Is there a class hierarchy browser?
- tumult 17y agoI hate you! I was looking for a Smalltalk->Javascript thing before I started my current project, but I couldn't find one other than st2js. Arrrgghhhhhhafuhoasdf asdfiojafdiojafdsooijfa Anyway, thanks, this is awesome.
- avibryant 17y agoIt's not really in the shape I would have wanted for a public release... kudos to the submitter for finding the website, I guess :). But if you find it useful, great.
- tumult 17y agoI always thought Smalltalk seemed like a closer match to JS than Scheme, if you got rid of first-class message passing. How much overhead is there? For example in Objective-J in reasonably tight loops, I usually try to avoid message passing or using the Cappuccino types if I can. JS is already pretty slow in IE and older browsers, and UI updates can become noticeably slower with more overhead.
- avibryant 17y agoThere's no overhead, in the sense that one Smalltalk message send maps to one Javascript method call. However, Smalltalk tends to use more, smaller methods, and more blocks, so there's some stylistic overhead that will make idiomatic Clamato slower than idiomatic Javascript.
- tlrobinson 17y agoDoes it support doesNotUnderstand?
- avibryant 17y agoNope. The goal here is not to duplicate every aspect of Smalltalk, only the ones that map easily to Javascript.
- sachinag 17y agoI thought Clamato was primarily a Mexican thing for Chelada (you can get pre-mixed Clamato and Budweiser in Mexico and Mexican areas in Chicago and other cities). I thought you Canadians were better than that. shakes head
- delano 17y agoTo the best of my recollection Clamato juice was created for the first time in Boston or New Jersey, but popularized via the Caesar in Calgary (like a Bloody Mary with Clamato instead of tomato). Either way, it's a prevalent drink in Canada and difficult or impossible to find elsewhere.
- BigZaphod 17y agoNo need for recollections when we have Wikipedia! http://en.wikipedia.org/wiki/Clamato http://en.wikipedia.org/wiki/Clamato Memory is so fallible anyway - why even use it? :P
- BigZaphod 17y agoSorry Avi - it's just so darned compelling... :P
- avibryant 17y agoYou can do penance by submitting some patches.
- stcredzero 17y agoThere are several departures from Smalltalk’s syntax and semantics. The most notable of these are: no explicit returns, 0-based indexing, no metaclass hierarchy, special syntax for instance variables. I can live with no metaclasses. Special syntax for instance variables isn't that much of a problem. 0-based indexing -- this should be easy to take care of with your own collection classes. However, no explicit returns -- this one kills me. I guess this has to do with Javascript. EDIT: JS has exception handling, so this could be used to implement explicit returns.
- abbat 17y agoI suggest some relization of explicit conditional return for Clamato: http://sites.google.com/site/abbatfilestore/clamato/cookbook/explicitconditionalreturnsupport http://sites.google.com/site/abbatfilestore/clamato/cookbook... Also, please join to Clamato google group: http://groups.google.com/group/clamato-smalltalk/ http://groups.google.com/group/clamato-smalltalk/
- gruseom 17y agoThe problem with using exception handling for explicit returns is that you'd need to put a try/catch block at the top level of every function. That seems yuck. Or am I missing something?
- avibryant 17y agoExactly. For those times that you really need them, I added a #return: method that you can use explicitly: self return: [:ret | .... ret value: foo ...]. But you only pay the cost of the try/catch/throw when you actually use it. FWIW, I've found that the lack of explicit returns really isn't a problem, at least in the code I've written and ported so far.
- gruseom 17y agoI've been offline for a few days and just read this: But you only pay the cost of the try/catch/throw when you actually use it. Do you mean that the existence of an explicit return is recognized at compile time, so only the functions that actually contain one need to be wrapped in a try-catch? Now that I think of it, that seems like the best way to do it. I've wanted to be able to compile return-from into JS for a while...
- akkartik 17y agoAfter all these years reading about it, the clamato tutorial was the first time I got to actually try out a code browser interface. Very cool.
- lucifer 17y ago"a browser fit for the gods" <G>
- akkartik 17y agoCode: http://bitbucket.org/avibryant/clamato http://bitbucket.org/avibryant/clamato
- ggchappell 17y agoThe use of JS as an object code seems to be a big trend lately. This makes me wonder: (1) How suitable is JS for use as an object code? (2) Is this trend taken into account by those designing the future of JS?
- olavk 17y ago(1) Depends on how different the source language is from the semantics of JS. JS is a high-level language and doesn't have e.g. goto which would make it easy to implement different execution models. If you don't want to create your own interpreter in JS (which would be an alternative to code generation), you have to be manage with functions (and exceptions). If the source language require more powerful constructs like goto or continuations, you are out of luck. (Theoretically you could gain some power by compiling to a continuation-passing style, but since JS engines doesnt have TCO, I dont think this would work in reality. The scoping rules combined with the distinction between expressions and statements means that it is harder to generate composable snippets. For example you cannot just generate a small "context free" code snippet with a local variable - the scope of a variable is always the function, so you need either to mangle the name to create a unique variable, or create an inline function and call it - but that changes the semantics of return, which again is a hindrance to composability. I would definitely prefer something like scheme as a compilation target, but it could be a lot worse. Imagine compiling to VBScript :-) For my particular project which compiles ES5/Harmony to JavaScript it works quite well, but those languages are based on JavaScript anyway, so that is almost cheating. (2) AFAIK the working group are a aware of the interest in JS a compilation target, but are not at the time considering adding features specifically to make it more suitable for that purpose.
- BigZaphod 17y agoI can't answer either of these very well myself, (although for #1 I speculate that it's prototypical nature makes it easier to target than a class-based language might be), but I think it's primarily targeted by language experimenters because it's incredibly ubiquitous and easy to demo to others (there's nothing new to install) and the coming generation of JS engines are finally using a lot of cutting edge techniques to drastically improve performance which should make their work more practical in the near future.
- jdp 17y agoThe script hangs and freezes in my browser, even on the tutorial page. I get the wait/stop script prompt every time I reload it. I'm using Firefox 3/Ubuntu.
- avibryant 17y agoGood to know - it definitely works best in Safari and Chrome right now (since they have the best-optimized JS implementations). I'm surprised Firefox is hanging that badly but I'll look into it.
- extension 17y agoThe search filter seems a bit too eager. Type one letter and it tries to enumerate scrillions of methods, which kills Firefox. It's probably the DOM manipulation specifically. Are you adding the results in one big innerHTML assignment? You can also try breaking the search into small chunks with setTimeouts between them.
- avibryant 17y agoThe problem is actually, more or less, building up the search index - this is only an issue the first time you do a particular kind of search, and it's fast after that. This involves parsing all the source code, which is a recursive process, which FF doesn't optimize (whereas Safari and Chrome zip through it much faster).
- s3graham 17y agoWow, slick! Browser for environment/introspection is definitely a killer feature. What does "save/commit" do? Is there a git-y thing behind it? It'd be nice to be able to have it auto-push to github et al. I get a generic "Error committing to counter.st" when I try to follow the tutorial though right now, using Chromium nightly on Ubuntu. (Trying to think of a project that could be called Caesar... ;) edit: oops, can't read: the browser's already called Caesar.
- avibryant 17y agoSave modifies the method in the current environment. Commit does an HTTP PUT back to the webserver (which, on clamato.net, is not configured to accept PUTs, so that will always error). You end up with .st files you can manage in git or anything else. You should be able to just ignore the commit errors and keep going through the tutorial, I think? But to get rid of them, just search for the "save" method, and remove the line that says "self commit", and then save it.
- extension 17y agoThe current Ruby to JS project: http://www.ntecs.de/projects.html http://www.ntecs.de/projects.html After some recent ambitious JS development, it's become clear to me that the language is just unsuited to large scale development and no library is going to change that. As such, I am really keen on these compiler projects, but I think it's a mistake to avoid language features because they are difficult to implement in JS. Syntax is nice, but it's those language features that are really needed.
- avibryant 17y agoIt depends on your goals. For me, it's not so much about difficult to implement as whether the generated JS is idiomatic enough for the various optimizing JS implementations (V8, SquirrelFish, TraceMonkey) to handle it. With Clamato, we've shied away from implementing language features until we could see how to do them in a way that wouldn't hurt optimization (the only exception I can think of is the Smalltalk cascade syntax, which is implemented naively and slowly for now, but it's obvious that with a bit more work it could be sped up).