Re: Fruit basket program in Nemerle

n_fruit.exe
n_fruit.exe has encountered a problem and needs to close.  We are sorry
for the inconvenience.
If you were in the middle of something, the information you were working on might be lost.
Debug Close

Octavian

----- Original Message ----- From: "Jamal Mazrui" <empower@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Saturday, November 10, 2007 12:03 AM
Subject: Fruit basket program in Nemerle


From the zip archive at
http://www.EmpowermentZone.com/n_fruit.zip

This fruit basket program is written in Nemerle  -- Full source code in
the zip archive and pasted below.  The batch file, compile.bat, builds the
executable, n_fruit.exe, which is about 12K in size.  No other files are
needed to run the program -- as long as the .NET Framework 2.0 is
installed.

Nemerle is an open source, .NET-based language, originating at a
university in Poland, and named after a character in a novel called "A
Wizard of Earth."  The language is a superset of C#, with modifications
and extensions to add features of functional languages like Haskell and
Lisp.  Although Nemerle programs are generally strongly typed at runtime,
a dynamic style of coding is usually possible because the compiler tries
to infer types from context.  Its official web site is at
http://Nemerle.org

The fruit basket code is the result of a conversion from C#, via the
cs2n.exe utility included in the Nemerle distribution.  For comparison,
the archive includes the original C# source code, as well as another
automatic conversion to the Boo language, via the web form at
http://codeconverter.sharpdevelop.net/Convert.aspx

I have also prepared a collection of Nemerle documentation at
http://www.EmpowermentZone.com/n_doc.zip

Jamal

/*
content of n_fruit.n
Fruit Basket program in Nemerle
Public domain by Jamal Mazrui
*/

namespace FruitBasket {
using System;
using System.Windows.Forms;

// define class inherited from Form
class FbForm : Form {
mutable  lblFruit : Label;
mutable  txtFruit : TextBox;
mutable  lblBasket : Label;
mutable  lstBasket : ListBox;
mutable  btnAdd : Button;
mutable  btnDelete : Button;

// define constructor
public this() {
// set window title
this.Text = "Fruit Basket";

this.Width = 400;
this.Height = 285;

// create two rows of controls with three controls in each row
// label, textbox, button and label, listbox, button
lblFruit =  Label();
lblFruit.Text = "&Fruit:";
lblFruit.Left = 14;
lblFruit.Top = 14;
lblFruit.Width = 44;
lblFruit.Height = 16;

txtFruit =  TextBox();
txtFruit.Left = 64;
txtFruit.Top = 14;
txtFruit.Width = 200;
txtFruit.Height = 16;

btnAdd =  Button();
btnAdd.Text = "&Add";
btnAdd.Left = 272;
btnAdd.Top = 14;
btnAdd.Width = 100;
btnAdd.Height = 20;
//  make it the default button
this.AcceptButton = btnAdd;

// Define event handler
btnAdd.Click += fun( o : object, e :  EventArgs) {
mutable  sFruit = txtFruit.Text;
if (sFruit == "")
{ {
MessageBox.Show("No fruit to add!", "Alert");
();
}
}
else { {

lstBasket.Items.Add(sFruit);
txtFruit.Text = "";
lstBasket.SelectedIndex = lstBasket.Items.Count - 1;
}
}
};

lblBasket =  Label();
lblBasket.Text = "&Basket:";
lblBasket.Left = 14;
lblBasket.Top = 38;
lblBasket.Width = 44;
lblBasket.Height = 16;

lstBasket =  ListBox();
lstBasket.Left = 64;
lstBasket.Top = 38;
lstBasket.Width = 200;
lstBasket.Height = 200;

btnDelete =  Button();
btnDelete.Text = "&Delete";
btnDelete.Left = 272;
btnDelete.Top = 38;
btnDelete.Width = 100;
btnDelete.Height = 20;

// Define event handler
btnDelete.Click += fun( o : object, e :  EventArgs) {
mutable  iFruit = lstBasket.SelectedIndex;
if (iFruit == -1)
{ {
MessageBox.Show("No fruit to delete.", "Alert");
();
}
}
else { {

lstBasket.Items.RemoveAt(iFruit);
when (iFruit > lstBasket.Items.Count - 1) {iFruit = lstBasket.Items.Count
- 1;}
lstBasket.SelectedIndex = iFruit;
}
}
};

// add controls to form
this.Controls.AddRange(    array[lblFruit, txtFruit, btnAdd, lblBasket,
lstBasket, btnDelete]);

// center form on screen
this.StartPosition = FormStartPosition.CenterScreen;
} // FbForm constructor

// define main entry point of application
static Main() :  void {
Application.Run( FbForm());
} // Main method
} // FbForm class
}
// FruitBasket namespace

__________
View the list's information and change your settings at
http://www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at http://www.freelists.org/list/programmingblind

Other related posts: