animated GIF GDLA Logo
Welcome
Structure
Members
FoundersWhat is GDL?
Tools
News
GDL Rocks
Info
World

French

German

Japanese

Portuguese

Spanish

 to The GDL Alliance  >  What is GDL?  >  Programming
What is GDL?ProgrammingParametric ExamplePella WindowGDL Object

So, you think you can't program...

by David Nicholson-Cole

>> Spanish Version

Well you can! – squirrels can program, birds can program, spiders do it, small children do it – in that they plan a series of actions, they try to get them in the right order, they correct their own mistakes when the make them, and they achieve a result – perhaps a hoard of nuts, a nest full of eggs, a web, or a Lego model.

The British Standards Institute recently (Sept '99) received the 'Ig Nobel' Price for Literarture in that they wrote BS.6008: Method for Preparartion of a Liquor of Tea, and took 5000 words to do it, going into the minutest detail! We will not go quite so far, but let's use tea making as an example of human programming. Let's write down a series of 'Operations' involved in making Tea. Without going into too much detail, list the sequence of operations to somemone who knows the obious things like how to turn on taps. Anybody reading this (above the age of 7) should be able to recite the following list in the right order.

1. Fill Kettle with water
2. Boil Water
3. Get teapot
4. Fill teapot with bags
5. Fill with water
6. Get cups
7. Wait until ready
8. Pour out
9. Add Milk
10. Serve Tea
 100: !Fill Kettle with water
200: !Boil Water
300: !Get teapot
400: !Fill teapot with bags
500: !Fill with water
600: !Get cups
700: !Wait until ready
800: !Pour out
900: !Add Milk
1000: !Serve Tea
Now because we are going to teach a computer how to make tea, you need to rewrite the list giving each Operation a number (with a colon), and use an exclamation mark to make each Operation name into a Label. For a human, you might number each task 1, 2, 3, etc, but for computers its easier to use larger numbers (because later, you could insert extra things you hadn't thought of.)

Next, you look at each Operation and realise that none of them are single Actions. Each Operation consists of a number of Actions which might include Error Checking. For example, if the teapot contains last night's teabags, then Wash Teapot. This might require quite a lot of IF statements, and then the Actions taken as a result of the IF statements. Depending on the level of knowledge or stupidity of the machine, you instruct it appropriately. For example we assume here that the machine knows how to turn a tap or a kettle on. In the same way, GDL knows that Cylinders are round and that Cones are tapered and round without us having to define 'roundness' mathematically.

The final program for making tea

Goes round until kettle filled: 2 IF statements
100: !Fill Kettle with water
IF kettle (empty) THEN (Fill kettle with water)
IF kettle (filled) THEN GOTO 200: !Boil water
A single line way of writing two IF statements
200: !Boil water
IF water (boiling) THEN (turn kettle off) ELSE (boil water)
People are 'integer' quantities; but this makes doubly sure that you can make tea for 2.
300: !Get teapot
IF (number of people) less than 2.01 GET smallteapot
IF (number of people) greater than 2 GET largeteapot
IF teapot (dirty) THEN (wash out teapot) UNTIL (clean)
IF teapot (clean) THEN (swirl hot water) UNTIL (worm)
IF teapot (warm) THEN (Fill teapot with bags) !continue
For the 'parameter' of tea, you could let the user select from a list of choices.
400: !Fill teapot with bags
LET teatype=USERCHOOSE(EarIGrey,Lopsong,Camomile,Tetleys)
IF teapot (large) THEN add 2 teabog USING teatype
IF teapot (small) THEN add 1 teabog USING tentype
In the event of a major problem you might have to jump back to the start.
500: !Fill with water
POUR water INTO teapot UNTIL (full)
IF (not enough water) THEN GOTO 100:
PLACE teacosy UPON teapot
START timeclock USING seconds
This is a repeating 'Loop', do it until all cups are selected and clean and in place.
600: !Get cups
REPEAT (in cupboard)
GET (a cup)
IF (cup dirty) THEN (wash cup)
PLACE cup ONTO tentray
UNTIL (enough cups for everybody)
This was going on while you were getting the cups.
700: !Wait until ready
IF TIMECLOCK less than 120 seconds THEN WAIT
Another repeating 'Loop'
800: !Pour out
REPEAT (on the teatray)
IF fullness=0 THEN POUR (a cup) UNTIL fullness=7/8
UNTIL (enough cups for everybody)
Another example of getting the parameter from the user's choice.
900: !Add Milk
LET milkcondition=USERCHOOSE(with milk,without milk)
REPEAT (for each cup on the teatray)
IF milkcondition=(with milk) THEN (add milk to cup)
UNTIL (each cup tested)
1000: !Serve Tea
Now this isn't written in BASIC, and it isn't written in GDL, but it's close to both of those two, and shows that programming can be like writing in English in a slightly mathematical style. OK, we can't all be perfect. The British Standard says put the milk in the cup first, and of course, I haven't tested to see if the users have chosen sugar, or want spoons, saucers or biscuits. And what happens if there isn't enough tea for everyone? Then you have to loop back and top up the teapot, or even reboil the kettle. This could be built into the program. That level of detail and error correction would make the program more professional and user friendly.

I hope this shows the sort of thing you can do, and has persuaded you that you can indeed write a program.
©2001 GDL Alliance / Last update Wednesday, March 19, 2003
[Welcome] [Structure] [Members] [Founders] [Tools] [News] [GDL Rocks] [Info] [World]