What is Marvin

Marvin is a programming language that was designed with DCI in mind. It builds heavily on C#. The first versions of Marvin can be seen as extensions to C# where versions in the road map will most likely reshape some of the fundamentals to provide even better support for DCI

This section of fullOO.info will onlhy deal with the parts of the Language that is different from C#. The reader is expected to have a general understanding of developing using C#

The new concepts introduced in Marvin

Marvin introduces a few new concepts that are not present in C#.
The most fundamental being role
A role is part of a context and can have a number of RoleMethods and a contract associated with it. The grammar for a role declaration looks as follows:

    role_declaration
    : ROLE IDENTIFIER opt_role_type
      {
      opt_contract
      opt_role_method_declarations
      }
    

The simplest role that can be defined would be one with out a contract or RoleMethods and that has no type requirements either. SUch a declaration would look like this:

role Amount {}

Quite often you would want to constrain the types of object that can play such a simple role. In the case where you'd want only objects of type decimal to play the role the declaration could be changed to:

role Amount : decimal {}

Roles can of course be more complex than that. For one they can include role methods. In the MoneyTransfer example there's a role called Source it's definition looks similar to

     role Source{
            void Withdraw(decimal amount){
                self.DecreaseBalance(amount);
            }
            entry void Transfer(decimal amount){
                Console.WriteLine("Destination balance is: " + Destination.Balance);
                Console.WriteLine("Source balance is: " + Source.Balance);

                Destination.Deposit(amount);
                Source.Withdraw(amount);

                Console.WriteLine("Source balance is now: " + Source.Balance);
                Console.WriteLine("Destination balance is now: " + Destination.Balance);
            }
        }
There's two RoleMethods defined for the Source role.

Transfer is also mark as entry point. This makes transfer callable from an interaction where Withdraw is only callable from another RoleMethod.

The last part to a role is the optional contract. Instead of specifying that a RolePlayer must be of a specific type, you can choose to declare that a RolePlayer must fulfill a contract. Fulfilling a contract is to have a matching method for each of the functions given in said contract. In the below declaration of the Source role the contract has one method called DecreaseBalance that takes an amount of type decimal and has the return type void

     role Source{
            contract {
               void DecreaseBalance(decimal amount);
            }
    
            void Withdraw(decimal amount){
                self.DecreaseBalance(amount);
            }
            entry void Transfer(decimal amount){
                Console.WriteLine("Destination balance is: " + Destination.Balance);
                Console.WriteLine("Source balance is: " + Source.Balance);

                Destination.Deposit(amount);
                Source.Withdraw(amount);

                Console.WriteLine("Source balance is now: " + Source.Balance);
                Console.WriteLine("Destination balance is now: " + Destination.Balance);
            }
        }