Tag Archives: expressions

Blocks as expressions

The irony is the moment I finished this feature I realized it is not enough — I need also a tracking system which would allow to postpone initialization.

But at least when you need to do some precomputation and then initialize variables you can use entire block as initialization value:

let (yyyy,mm,dd)
  = * do
        let parts = s.split("-");
        // the outcome of the entire do-end block
        parts ++ "".copy((3-parts.count()));

It is better than nothing but I would prefer to write:

let yyyy,mm,dd Int; // postponed initialization
  let parts = s.split("-");
  // initialization
  (yyyy,mm,dd) = *(parts ++ "".copy((3-parts.count())));

In both cases temporary variable parts does not leak, but I am more used to the latter form. On the other hand only the former will work with loops, unlike in Scala which returns just unit (void in Skila) I am going to add some muscles to them.

Tagged , ,

Expressions everywhere plus optional parallel assignments

The more I work on Skila the more I appreciate features with uniform behaviour. Lately I tried to add basic tail call optimization for current function — nothing more is required than reassigning the arguments and jumping to the top of the function.

But since I use PHP as backend which has very strict distinction between expressions and statements I failed — function call is an expression and jump (goto) is a statement. This was enough to motivate me to rewrite language part of Skila to make all statements, control structures expressions. They don’t produce any values yet, it will take more effort than just changing grammar.

The second solid change is support for optional parallel assignments (and declarations). You could of course write such code by hand:

if year ?= (y_str to ?Int) 
   and month ?= (m_str to ?Int) then

But consider what will happen when month conversion fails — year part will be altered. Maybe it is intended, maybe not — for the latter case Skila provides transaction-like assignment:

if (year,month) ?= (y_str to ?Int , m_str to ?Int) then

The variables will be updated only if both conversions succeed.

Tagged , , ,