Cyan syntax

In C++ and Java functionality usually ends up entirely within a class. But OOP principles suggest that any functionality that can reside outside the class should. In C++ it's easy to do this by writing external functions, but then there is an obvious distinction between class-functions and external functions.

object.internal(1, 2);
external(object, "Hello");

I'm thinking of using the external syntax for all function calls.

internal(object, 1, 2);
external(object, "Hello");

This also has the advantage of using English-like verb-object syntactical order.

Properties can still use the traditional object-property order, but there's really no need for the dot . access operator. Instead, how about using it to end statements (instead of semi-colons)? So

if array length > 5:
    append(array, 6).

Need a more flexible inheritance syntax, to allow the programmer to rename members, resolve name clashes, etc., when using multiple inheritance.

class HashTable:
    inherit List:
        ...

    inherit Dictionary:
        ...

Defining control structures

Could allow the definition of arbitrary control structures. The only primitive flow control mechanisms would be if and goto. for, while, etc. could be provided in the standard library.

control function for each variable in collection body:
    class parameters:
        Item       is Object
        ResultType is Object

    parameters:
        scope      is Scope
        variable   is Identifier
        collection is Collection(Item)
        body       is Block(ResultType)

    returns:
        Collection(ResultType)

    variables:
        iterator   is Collection(ResultType).Iterator
        results    is Collection(ResultType)

    scope.add(variable.name, Item)

    iterator := collection.first
    results  := <Array(ResultType): collection.size>

    loop:
        if iterator = null:
            goto end

        scope   .assign(variable.name, iterator.value)
        results .add   (body.execute(scope))
        iterator.next  ()

        goto loop

    end:
        return results

Is this necessary? Would it be easier to just modify the compiler?

Edit this page | 6 years, 4 months old