Friday, January 17, 2020

Crack 1.6 Released

We are pleased to report the release of crack 1.6.  This version focuses on a few features that I have wanted to add to the language for a long time:

The "is not" operator ("!is")

This fixes a long-standing wart.  Up until 1.5, the only way to check if an object is "not identical" to another object was to negate the result of "is".  Since this is a very common thing to do when verifying that an object is not null, the codebase was scattered with code like "if (!(x is null))" which is as painful to read as it is to type.

1.6 adds the "!is" operator (which is simply syntactic sugar for "!(a is b)").

Safe Navigation 

It's not uncommon to have a sequence of field dereferences where you want to check every step along the way for null and return a null (of the type of the final dereference) if one of those dereferences fails the check.  Many modern languages support doing this in a very lightweight form using the "safe navigation" operator.  Crack is now among them.  So we can now say:

x := foo?.bar()?.baz;  # x is null if foo, or
                       # is null

Attribute Accessors

It is useful to be able to use the same syntax for field access whether a field is being accessed directly or via a method (i.e. a "getter" or "setter"). Crack 1.6 now provides this by allowing you to define accessor methods:

class Person {
    # We would normally just define "String name" as our field
    # unless we needed to do something special but this 
    # illustrates the usage of the feature.
    String __name;
    String oper .name() { return __name }
    String oper .name=(String val) { return __name = val }

cout `$(\n`; = 'Frodo';

There's also the usual round of bug fixes and smaller features.

So check it out at

Happy hacking!