2010-08-04

Puzzled by locking in Vala?

If you can't wrap your head around how Vala locks variables, take a look at this great article about locking in Vala by Jim Nelson.
Apart from explaining how it actually works, he also compares it to Java, which is perfect if you come from that strange world :).

http://www.yorba.org/blog/jim/2010/08/synchronization-in-vala.html

2010-07-27

Vala 0.9.4 released

Hello,
a new version of the Vala compiler has been released. This version does not introduce major features but mostly bug-fixes and Dova profile enhancements:
  • Append documentation comments to generated C files.
  • Skip <doc> tags in .gir files.

  • Various improvements to the Dova profile.
  • Many bug fixes and binding updates.
As usual, you can find more information at live.gnome.org/Vala.

2010-07-14

Vala 0.9.3 released and documentation news

Hello,
this 0.9.3 release of the Vala programming language adds many interesting features as well as many bug fixes and binding improvements. Also I'd like to point you out to the new collaborative Vala Reference Manual and Hackers' Guide to Vala. The release notes:
  • Support newlines in double quoted string literals.
  • Add experimental support for main blocks.
  • Add experimental vala tool to compile and run code.
  • Initial support for generic delegates.
  • Support using GClosure for delegate parameters.
  • Support GBoxed-based memory management.
  • Improvements to the .gir reader and writer.
  • Various improvements to the Dova profile.
  • Many bug fixes and binding updates.
Check out the Vala home for more information and download.

2010-07-11

Vala for scripting

Hello,
the upcoming release of Vala will have basic scripting capability (mostly for small tests). Yes, this sounds weird, but it's more trivial than what you expect. The installation will create a symbolic link /usr/bin/vala -> /usr/bin/valac that you can use to run vala scripts.

Also, vala scripts can have implicit main(), so that it becomes faster to write test scripts. An example:
#!/usr/bin/env vala
message ("test");
Save it as test.vala, now you can either chmod +x test.vala and run ./test.vala or just vala test.vala.
Valac will automatically compile the script and run it. After that the executable will be deleted, which means there's no cache.

This feature is of course experimental and it's not currently possible to import other vala files.

2010-06-24

Vala and Monads

Hello,
I've been reading around lately about functional monads written in imperative languages, then I've tried to bring them to Vala. I'm not going to explain what a monad is, there's a lot of papers out there.

If you want to test the code below you need Vala git master (more recent than 0.9.2).

First of all we need a basic framework and some monads you can immediately read here.
Notice some comments are in do notation and that related functions are really only utilities to let the example code below be more readable, they respect the functional semantics of monads without adding more imperative power.

The only difference with other implementations is that BindFunc not only passes the underlying value but also the return function. This is helpful to avoid keeping monads around in termporary variables.

Now let's port some Haskell typic examples to Vala:

safe_div a b = if b == 0 then Nothing else Just (div a b)

Monad safe_div (int a, int b) { if (b == 0) return nothing; return new Just (a/b); }

The nothing variable is initialized with Nothing.instance which is a singleton.
Now let's map a simple multiplication function:

bind_and_mul monad factor = do { x <- monad; return (x*factor); }

Monad bind_and_mul (Monad monad, double factor) {
return monad.bind ((v,unit) => unit (((int)v) * factor)) as Monad;
}

Pretty easy, we get the unpacked value and multiply it with the given value.

Things get a bit longer with list monads. We want that given an x the function returns [x,x+1]:

bind_and_list_plus monad val = do { x <- monad; return [x,x+1]; }

Monad bind_and_list_plus (Monad monad, int val) {
return monad.bind ((x,unit) => {
var l = new List (); l.add (x); l.add (((int)x)+val); return unit(l);
});
}
Ok, but what is the result of those weird definitions?

Haskell: do { x <- safe_div 5 2; return (x*2); }
Vala: bind_and_mul (safe_div(5,2), 2);
Result: Just (4)
What if we divide by zero?

do { x <- safe_div 5 0; return (x*2); }
bind_and_mul (safe_div(5,0), 2);
Result: Nothing
Transform -10 into some useless list:

do { x <- -10; return [x,x+1]; }
bind_and_list_plus (new Just (-10), 1);
Result: [-10,-9]

Now do the same transformation for a list:

Haskell: do { x <- [1,2,3]; return [x,x+2]; }
Vala: var l = new List(); l.add(1); l.add(2); l.add(3);
bind_and_list_plus (l, 2);
Result: [[1,3],[2,4],[3,5]]

Again, the complete code with test cases can be found here.

2010-06-20

Vala 0.9.2 has been released

Hello,
this new release follows the huge changes coming along with GLib and GTK+ latest releases:
  • Initial support for GDBus-based clients and servers.
  • Support implicit and explicit GVariant casts.
  • Add support for [Deprecated] attribute.
  • Add GenericArray as alternative binding to GPtrArray.
  • Add gdk-pixbuf-3.0, gdk-3.0, gdk-x11-3.0, and gtk+-3.0 bindings.
  • Updates to the GLib bindings.
  • Many bug fixes.
Stay tuned with furter updates.

2010-06-08

Vala 0.9.1 is out

Hello,
yesterday the announce of the 0.9.1 release of Vala. You can find release notes here.
This is more like a transitional development release torward a new 0.8.x branch stable release.

Changes

  • Support constants in enums.
  • Deprecate +=/-= syntax to connect/disconnect signal handlers.
  • Add experimental support for Dova profile.
  • Update Genie parser (Jamie McCracken).

  • Add clutter-gst-1.0 bindings (Ali Sabil).
  • Add gdu and gdu-gtk bindings.
  • Add libesmtp bindings (Adrien Bustany).
  • Add mx-1.0 bindings (Evan Nemerson).
  • Add orc-0.4 bindings (Fabian Deutsch).
  • Add rest-extras-0.6 bindings (Adrien Bustany).
  • Updates to the GLib, GStreamer, Linux, SQLite, and other bindings.
  • Many bug fixes.