sábado, 17 de septiembre de 2011

Amber language (former jtalk), digging deeper

Lots of changes have happened in jtalk world since last week.
  • Jtalk is now Amber. The project has changed its name when the 0.9 release happened. That means that the repo is now different, and the website too.
  • JQuery bindings have been removed from the system. Now we can access javascript objects directly, and use asJQuery in the same way, so there's no drawback, only the way to deal with jquery is more smalltalkish. Counter new appendToJQuery: 'body' asJQuery works perfectly, so no problem.
Creating functions
If you want to know a bit more on amber, you have to keep in mind that it's a smalltalk, so you can explore everything in your IDE. Let's try to find out a bit more on how the compilation from smalltalk to js works. This will allow us to debug our in a lower level than usual, and find glitches in our codes, or detect where our closure is missing the variables (when interfacing with js, sometimes it's useful to see the whole js code, and make conclusions on js).

Let's create a new class Foo with a method that gets a block (callback) and executes it. Now, to find out how it's compiled, we'll make amber print the compiled source of the method:
(Foo methodDictionary at: 'get:') fn compiledSource "print it".

If we print it, the result will be the js source of the method

You can try variations like returning explicit values, try to pass instVars to the closure, and see what is the translation to js. This helps sometimes to find out your way.

Can I inspect?
Inspector is there, but for the moment, it's in very early stage.

Debugger is also there, also in early development. You can see the stacktrace, and inspect the methods, but not changing values and so.


We can use amber for the server side, running the generated javascript on node.js. Due to the hability of Amber to interoperate with plain js, we can use a shitload of libraries from amber. Here follow a couple of examples of amber on node.js

Nicolas Petton wrote a fileserver meant to be used in the node.js side. This allows us to commit changes to our files transparently without the need of webdav,python(see last post), or any external server. It's Amber all way down.

The usage is fairly easy. Just cd to the root amber directory and run ./bin/server, that will run ./server/FileServer* things.

Trying the node.js part of amber, we can try to build a small program, and as no programming language is complete unless it has a IRC bot in it, let's solve this issue:) Btw, I hacked a couple of emacs functions to deal with st files a bit better.

3 comentarios:

Anónimo dijo...

Thanks for this article! I've just started tinkering with Node and Amber/Smalltalk.

But I'm stuck! Could you add some more details on how to run the IRCBot example?

I managed to compile the code and load it in the class browser, but smalltalk.IRCBot._initialize() raises an error: require is not defined.

Anónimo dijo...

Nevermind! I am an ass, I was trying to run the code inside the browser. I figured everything out after reading the examples in examples/nodejs. Nice.

Raimon Grau dijo...

Oops, too late but anyway: Glad you had it working in the end.

Thanks for visiting!