Boo fruit basket program without indentation requirement

From the archive at
http://EmpowermentZone.com/boo_fruit.zip

This fruit basket program is written in Boo.  This free .NET language
borrows syntax from Python and Ruby, seeks to improve it, and combine
strengths of static and dynamic languages.  Its home page is at
http://boo.codehaus.org

I was able to produce working boo_fruit.boo code by converting a C# fruit
basket program via a web form available at
http://codeconverter.sharpdevelop.net/Convert.aspx
For comparison, the C# code is available in the file cs_fruit.cs.

The file optimal.boo contains a more concise, optimized version in Boo.  I
later added simpler.boo, an even shorter and cleaner version.

Further still, I have now added wsa.boo, a "white space acgnostic" version
that relies on the -wsa compile parameter.  This shows how Boo code may be
written with end statements rather than required indentation, as pasted
below.  It is probably the friendliest code of any fruit basket program I
have done to date.

The included batch file compile.bat or compile_wsa.bat invokes the
command-line compiler with appropriate parameters.  The archive also
includes the boo command-line compiler, booc.exe, and Boo interactive
interpreter, booish.exe, as well as related DLLs.  Similar to the
interactive environment of Python, Booish lets one test code and get
information about .NET types.

I have posted a collection of text tutorials on Boo at
http://EmpowermentZone.com/boo_doc.zip

Jamal

/*
content of wsa.boo
Fruit Basket program in Boo
Public domain by Jamal Mazrui
*/

# Import namespace
import System.Windows.Forms

# Create controls
tlp = TableLayoutPanel(ColumnCount : 3, RowCount : 2)
lblFruit = Label(Text : '&Fruit:')
txtFruit = TextBox()
btnAdd = Button(Text : '&Add')
lblBasket = Label(Text : '&Basket:')
lstBasket = ListBox()
btnDelete = Button(Text : '&Delete')
tlp.Controls.AddRange((lblFruit, txtFruit, btnAdd, lblBasket, lstBasket,
btnDelete))

# Define Add event handler
btnAdd.Click += def ():
sFruit = txtFruit.Text
return MessageBox.Show('No fruit to add!', 'Alert') if sFruit.Length == 0
lstBasket.Items.Add(sFruit)
txtFruit.Clear()
lstBasket.SelectedIndex = lstBasket.Items.Count - 1
end

# Define Delete event handler
btnDelete.Click += def ():
iFruit = lstBasket.SelectedIndex
return MessageBox.Show('No fruit to delete.', 'Alert') if iFruit == -1
lstBasket.Items.RemoveAt(iFruit)
iFruit -- if iFruit == lstBasket.Items.Count
lstBasket.SelectedIndex = iFruit if iFruit >= 0
end

# Finalize dialog
dlg = Form(Text : 'Fruit Basket', AcceptButton : btnAdd, StartPosition :
FormStartPosition.CenterScreen, AutoSize : true, AutoSizeMode :
AutoSizeMode.GrowAndShrink)
dlg.Controls.Add(tlp)
dlg.ShowDialog()

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

Other related posts: