Tag: Pascal

Haggis for anyone?

haggis2goOverview

Within the N5 Curriculum for Excellence in Scotland, it has been decided that pupils will use the Haggis pseudo code to define a programming problem, without the need for any specific programming language. This overcomes the problem of teachers not agreeing on a standard programming language. Personally having tried most programming languages, I would have recommended Pascal as being the nearest to pseudo code, and where there are many tools that can be used, but I do actually see the sense in not actually telling teachers which programming language they should use. As an academic, it doesn’t matter too much about the programming language that has been taught, as we will teach them the ones that industry currently uses. What does matter is that pupils should understand how to design programs, and produce code which solves a given problem – you can call it problem solving if you want – but it is one of the key skills for a computer scientist/engineer. If you are interested, the specification is here and you can try Haggis2Go Here.

Bright Red Digital Zone

brightred_logoYou may know of Bright Red Publishing, who they are a great company and who have the vision to not only create books for all the new N5 material, but, at the same time, create the Web-based material for them. We now work with them in trying to create a scaleable and robust Web infrastructure, where it becomes easy to port content from the books into a Web space, and how to encourage deep learning of the material in the books. If you are interested, it is here.

Haggis Pseudo Code Analyser

I’ve spent the last decade or so writing simulators for networking equipment, such as with my Cisco router simulator. For these I started off with Adobe Flash, then move the move to Microsoft .NET, and finally onto ASP.NET MVC. I must admit I think I made the right choice each time, as Flash proved not to be scaleable, then the move to .NET was a good one for a while, but as the world move to Web interfaces, the final move to ASP.NET MVC was the best move yet. Here are the .NET versions, and here is the MVC ones.

The Haggis pseudo code analyser is still under development, and there lots of this to do, but the figure below show the first attempt. Click here if you want to go to the site, and it is free to use just now, so just register if you are interested in try it out. If you have any constructive feedback, please send me it, as I’m keen to continue the development of the page.

hag

There’s a lot of work to be done in providing feedback on the commands, and so on, but I thought it would be good to at least make a start on this, and continue to develop it over the year. Thus I’ve added a few simple tutorials, which, at least, show the basic principles of the language, and perhaps how it could be used in the future. If you are interested, I basically convert to code into C# code and then run it. It will be simple to show the programming language output for Pascal, C, and many other languages. For just now, I’ve stuck with C#, as it’s the easiest to run on the server. I’ll add a code export option soon, so that users can see the generated code. For just now, there’s too many things that could go wrong with the conversion, so I’ve left it off.

Example 1

The following shows a simple example of sending a string to the display (Try):

haggis # LIST
haggis # SEND "hello" TO DISPLAY
haggis # SEND "goodbye" TO DISPLAY
haggis # LIST 
     SEND "hello" TO DISPLAY
     SEND "goodbye" TO DISPLAY
haggis # RUN 
     hello
     goodbye

Example 2

The following shows a simple example of setting a value and then displaying it (Try):

haggis # CLEAR
haggis # SET c TO 10
haggis # SEND c TO DISPLAY
haggis # LIST
 SET c TO 10
 SEND c TO DISPLAY
haggis # RUN
 10

Example 3

The following shows a simple example of setting a string to a variable and then displaying it (Try):

haggis # CLEAR
haggis # SET c to "goodbye"
haggis # SEND "hello" TO DISPLAY
haggis # SEND c TO DISPLAY
haggis # RUN
 hello
 goodbye

Example 4

In this example we perform a maths function and display the result (Try):

haggis # SET c TO 9*5
haggis # 
haggis # SEND c TO DISPLAY
haggis # LIST
 SET c TO 9*5
 SEND c TO DISPLAY
haggis # RUN
 45
haggis # SET d TO 9-5
haggis # RUN
 45
 4

Example 5

In this example we will use an IF (..) THEN conditional statement to make a decision on an expression (Try):

haggis # SET c TO 15
haggis # IF (c<10) then
haggis #  SEND "Less than 10" TO DISPLAY
haggis # END IF
haggis # RUN
haggis # IF (c>5) then
haggis #  SEND "Greater than 5" TO DISPLAY
haggis # END IF
haggis # RUN
 Greater than 5

Example 6

In this example we use a REPEAT…UNTIL loop to perform some operations (Try):

haggis # SET c TO 1
haggis # REPEAT
haggis #  SET c TO c+1
haggis #  SEND c TO DISPLAY
haggis # UNTIL c>20
haggis # RUN
2
3
4
5
6
7
8
9
10
11

Example 7

Sometimes you make a mistake in a program that shows up when you run it (known as a run-time error). One example of a run-time error is where a you put the program into an infinite loop (such as the example below). To catch this we have put in a loop break such as (Try):

haggis # SET c TO 1
haggis # REPEAT
haggis #  SET c TO c+1
haggis #  SEND c TO DISPLAY
haggis # UNTIL c<0
haggis # RUN
2
3
4
5
6
7
8
9
10
11
12
... 
21
Loop terminated ....

So if you see “Loop terminated ….”, it means that the program has broken the loop before it was meant to, and that you should perhaps check your code.

Example 8

Another type of loop is WHILE … DO. Which checks the loop expression at the start of the loop:

haggis # SET c TO 1
haggis # WHILE c<10
haggis #  SET c TO c+1
haggis #  SEND c TO DISPLAY
haggis # END WHILE
haggis # RUN
2
3
4
5
6
7
8
9
10

Postscript: If you thought you were coming to a food page … so sorry .. .BTW … I love haggis (as a food too).

SQL

Outline

SQL (Structured Query Language) has managed to sustain its interest in the Computing industry, having been first specified in 1970 by Edgar F. Codd’s. While software languages such as C, Pascal, and FORTRAN have all peaked and waned, it is SQL that has sustained itself, and is now one of the most ask-for skill in Computing. Why does it work so well? Well it’s because the designers got it right first time, and there has been very little need to change the overall structure of the language.

I currently use ASP.MVC for my Web development, and which hides a great the actual requests to the database, but underneath it is still using SQL requests. It is thus important for any computing student to understand its scope, and how it is used to get data from data sources. With this in mind I’ve created a range of SQL requests which illustrate the basic principles of SQL.

Simple Examples

I have created a simple table:

ID FirstName Surname FullAddress Test 1 Test 2 Gender Age
1 Fred Smith 10 Fake Street 10 20 M 30
2 Bert Smith 1 Round Lane 30 40 M 40
3 Bob Malcolm 5 Square Road 100 30 M 22
4 Eve Almond 11 Full Lane 45 40 F 56
5 Freddy Smith 111 Edinburgh Road 50 50 M 43

Using this, I have created a number of sample SQL commands which illustrate some basic features:

SELECT * FROM db1 Try
SELECT * FROM db1 ORDER BY Surname Try
SELECT * FROM db1 ORDER BY Surname DESC Try
SELECT * FROM db1 ORDER BY Age Try
SELECT * FROM db1 ORDER BY Gender Try
SELECT FirstName FROM db1 WHERE (Gender='M') Try
SELECT FirstName FROM db1 WHERE (Gender='F') Try
SELECT Surname FROM db1 WHERE (Gender='M') Try
SELECT Surname FROM db1 WHERE (Gender='F') Try
SELECT First(Surname) FROM db1 WHERE (Gender='M') Try
SELECT Last(Surname) FROM db1 WHERE (Gender='M') Try
SELECT Max(Age) FROM db1 Try
SELECT Min(Age) FROM db1 Try
SELECT FirstName FROM db1 WHERE (Surname='Smith' OR Surname='Almond') Try
SELECT Avg([Test 1]) FROM db1 Try
SELECT Avg([Test 1]) FROM db1 WHERE (Age>30) Try
SELECT Sum([Test 1]) FROM db1 Try
SELECT Sum([Test 1]) FROM db1 WHERE (Age>30) Try
SELECT Count(FirstName ) FROM db1 WHERE (Age<30) Try
SELECT Count(FirstName ) FROM db1 WHERE (Age>30) Try
SELECT Count(FirstName ) FROM db1 WHERE (Age=30) Try
SELECT FirstName,Surname FROM db1 Try
SELECT DISTINCT Surname FROM db1 Try
SELECT FirstName,Surname,Age,[Test 1] FROM db1 WHERE (Gender='M') Try
SELECT FirstName,Surname,[Test 1],[Test 2] FROM db1 WHERE (Gender<>'M') Try
SELECT FirstName,Surname,[Test 1],Age FROM db1 WHERE Age BETWEEN 10 AND 50 Try
SELECT FirstName,Surname,[Test 1],Age FROM db1 WHERE Age IN (22,56,33) Try
SELECT FirstName,Surname,[Test 1],Age FROM db1 WHERE Surname LIKE 'Sm%' Try
SELECT FirstName,Surname,[Test 1],Age FROM db1 WHERE Surname LIKE '[AaSsUu]%' Try
SELECT FirstName,Surname,[Test 1],Age FROM db1 WHERE Surname NOT LIKE 'Sm%' Try
SELECT Gender,AVG([Test 1]) FROM db1 GROUP BY Gender Try
SELECT FirstName,Surname,[Test 1] from db1 where Surname in ( 'Smith', 'Almond') ORDER BY Surname Try

Other examples

These examples use the following table:

ID Surname Firstname Age Gender Interest Country
7 Smith Fred 43 Male Soccer Scotland
8 Balley Bert 44 Male Rugby England
9 Allan Karen 20 Female Tennis USA
10 Carroll Kirk 25 Female Soccer Canada
11 Smith Allan 50 Male Golf Scotland
12 MacDonald Iain 22 Male Golf Scotland
13 McAlpine Carol 33 Female Tennis Mexico
14 Wilson Mike 33 Male Tennis England
15 Smith Karen 40 Female Golf USA
16 Buchan Martin 20 Male Football Scotland

For this you can try the following:

 SELECT * FROM Table1 Try
 SELECT * FROM Table1 ORDER BY Surname Try
 SELECT * FROM Table1 ORDER BY Surname DESC Try
 SELECT * FROM Table1  ORDER BY Age Try
 SELECT * FROM Table1  ORDER BY Gender Try
 SELECT * FROM Table1  ORDER BY Interest Try
 SELECT Surname,Interest,Gender FROM Table1  WHERE (Gender='Male') Try
 SELECT Surname,Interest,Gender FROM Table1  WHERE (Gender='Female') Try
 SELECT Surname,Interest,Age FROM Table1  WHERE (Age>30) Try
 SELECT Surname,Interest FROM Table1  WHERE (Interest LIKE 'S%') Try
 SELECT Max(Age) FROM Table1 Try
 SELECT Min(Age) FROM Table1 Try
 SELECT FirstName,Country FROM Table1 WHERE (Country='USA' OR Country='Canada') Try
 SELECT FirstName,Country FROM Table1 WHERE NOT (Country='USA' OR Country='Canada') Try
 SELECT FirstName,Country,Interest FROM Table1 WHERE (Country='USA' AND Interest='Golf') Try
 SELECT FirstName,Country,Interest FROM Table1 WHERE (Country='USA' OR Interest='Golf') Try
 SELECT Avg(Age) FROM Table1 Try
 SELECT Count(FirstName) FROM Table1 WHERE (Interest='Soccer') Try
 SELECT FirstName,Surname,Interest,Age FROM Table1 WHERE Age IN (22,40,42,56,33) Try
 SELECT FirstName,Surname,Interest,Age FROM Table1 WHERE Interest IN ('Golf','Soccer','Rugby') Try
 SELECT FirstName,Surname,Interest,Age FROM Table1 WHERE Interest NOT IN ('Golf','Soccer','Rugby') Try
 SELECT FirstName,Surname,Interest,Age FROM Table1 WHERE Interest LIKE 'R%' Try
 SELECT FirstName,Surname,Interest,Age FROM Table1 WHERE Interest LIKE '[RrSsUu]%' Try
 SELECT FirstName,Surname,Interest,Age FROM Table1 WHERE Interest NOT LIKE 'S%' Try
 SELECT * FROM Table2 Try
 SELECT * FROM Table1 UNION SELECT * FROM Table2 Try