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()));
      end

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

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

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.

Advertisement
Tagged , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: