Genie language updated

bearophile bearophileHUGS at lycos.com
Sat Oct 31 11:11:13 PDT 2009


I have shown here a little the Genie language in the past, it' a version of the Vala language with a cleaned up syntax. In the last months they have added several new things, some of them can be interesting for D too.

Beside few comments of mine, most of the following text is quoted from this page:
http://live.gnome.org/Genie

----------------

Logical operations use names instead of symbols, so writing && or || for mistake where you need a & or | (or the opposite bug) is avoided:

a and b
a or b
not (b)
a is not b
a is b

----------------

Nullable Types, they think they are a good idea, while so far this idea has shipwrecked in D:

By default, Genie will make sure that all reference point to actual objects. This means that you can't arbitrarily assign null to a variable. If it is allowable for a reference to be null you should declare the type with a ? modifier. This allows you to assert which types may be null, and so hopefully avoid related errors in your code. This modifier can be placed both on parameter types and return types of functions:

/* allows null to be passed as param and allows null to be returned */
def fn_allow_nulls (string? param) : string?
        return param
        
/* attempting to pass null as param will lead to that function aborting. Likewise it may not return a null value */     
def fn_no_null (string param) : string
        return param  

(Genie performs such checks at run time (they can be disabled), D has can totally avoid this.)

----------------

It even has built-in weak references, using the word "weak":

class Test
    Object o

    def get_weak_ref () : weak Object
        o = new Object()
        return o

Genie objects also have Events (aka Signals) by default.

----------------

Ownership transfer:

'#' is used to transfer ownership.

As a suffix of a parameter (or property) type. it means that ownership of the object is transferred. As an operator, it can be used to avoid copies of non-reference counting classes. e.g. 

var s = "hello"

/* s will be null when owner is transferred */
t : string = #s

print t

This means that s will be set to null and t inherits the reference/ownership of s. 

----------------

'ref' and 'out' modifiers:

A method in Genie is passed zero or more parameters. The default behaviour when a method is called is as follows:

    * Any value type parameters are copied to a location local to the function as it executes.
    * Any reference type parameters are not copied, instead just a reference to them is passed to the function. 

This behaviour can be changed with the modifiers 'ref' and 'out'.

'out' from the caller side
    you may pass an uninitialized variable to the method and you may expect it to be initialized after the method returns 
'out' from callee side
    the parameter is considered uninitialized and you have to initialize it 
'ref' from caller side
    the variable you're passing to the method has to be initialized and it may be changed or not by the method 
'ref' from callee side
    the parameter is considered initialized and you may change it or not 

----------------

Properties: one way to define them:

class Foo : Object
    prop name : string
    prop readonly count : int
    
    [Description(nick="output property", blurb="This is the utput property of the Foo class")]    
    prop output : string
        get
            return "output"
        set
            _name = value   

----------------

isa operator, similar to the semantically-overloaded dynamic cast in D, to see if a object is of a given Object type:

init
    var o = new list of string
    if o isa Object
        print "a list of string is an object"
    if o isa list of Object
        print "a list of string is a list of Object"
    if o isa Gee.Iterable
        print "a list of string implements Iterable"

----------------

Bye,
bearophile



More information about the Digitalmars-d mailing list