Skip to content

Define a mutable record

NN--- edited this page Apr 18, 2012 · 4 revisions

Define a mutable record

  • Category: Defining Types
  • Description: Define a mutable record
  • Code:
using Nemerle;
using System;
using System.Console;

[Record]
class Employee 
{
  public Name : string;
  public StartDate : string;
  public mutable Salary : double;
}

def steve = Employee(name = "Steve", startDate = "01 Jan 2000", salary = 30000.0);
def joe   = Employee("Joe", "25 Dec 2001", 45000.0);

def giveRaise(emp, increase)
{
  emp.Salary *= 1.0 + increase;
  WriteLine($"$(emp.Name) : Salary = $(emp.Salary)");
}

giveRaise(steve, 0.05);
giveRaise(joe,   0.10);
  • Execution Result:
Steve : Salary = 31500
Joe : Salary = 49500

[Copyright ©](Terms of use, legal notice)

Clone this wiki locally