The Northern Spy: a first look at Modula-2 R10
TweetFollow Us on Twitter

The Northern Spy: a first look at Modula-2 R10

By Rick Sutcliffe

Last month the Spy opined on the software crisis--safety, security, and reliability having been abandoned for quick-and-dirty-get-it-out-the-door and let the customers do our debugging, software has become prey for the black hats.

There are too many vulnerabilities in both commercial packages and the Internet, and one day this house of cards is going to come crashing down upon us all. We have sound software engineering techniques and universities such as the ivory basement where the Spy toils do teach them--but they are not used because too few developers are university trained, too many managers haven't a clue what those principles are, and have other priorities that do not necessarily eventuate in quality code, and too many people use tools that are not optimized for producing that quality code--even mitigate against doing so.

This month, the Spy will begin presenting a new dialect of Modula-2 that he and Telecom engineer Benjamin Kowarsch have been working on since 2008. Since recent inductees into the developer fraternity will not be familiar with Modula-2, we begin with the basics--not "hello world", but the simple solution to a class of problems often encountered in the sciences, and holding down a minor character position in one of the Spy's new novels.

Population systems generally grow or decay in the short term proportionally to the number of individuals. That is:

And, as every first year calculus student knows, such differential equations have solutions of the form:

where t is in time units, A0 is the initial population, and k is an experimental constant that is positive for growth and negative for decay. Of course, this may be simplistic, as other factors, such as maximum population loads and predation may complicate the model, but there are may problems, including continually compounding interest, radioactive and other decay, and short-term growth that do follow the simple model.

In the case of decay, it is often convenient to put things in terms of half-life, that is the time that it would take for half the population or quantity to decay. Here we have:

so that or whence where T is the half life.

Thus, if either k or the half life is available (and tables of chemical properties publish both) the remaining amount of an initial quantity after a specified time can be easily computed. The following Modula-2 R10 program illustrates this solution, and some simple points about the syntax--both the familiar and the new.

(* This program demonstrates a simple Modula-2 R10 solution.
It computes exponential growth or decay amounts. *)

MODULE GrowthAndDecay;
IMPORT IOSupport;
FROM StdIO IMPORT stdIn, stdOut, WriteLn, SkipLine;
IMPORT ASCII, RealMath;

TYPE
ProblemType = (growth, decay);

VAR
initialAmount, finalAmount, k, time : REAL;
thisProblem : ProblemType;
ans : CHAR;
useHalfLife, doAgain : BOOLEAN;

BEGIN
useHalfLife := FALSE;
WRITE ("This program computes amounts of an exponentially growing or decaying population remaining after a specified time.\n");
WRITE ("Note that when providing numerical answers, real format must be used--a decimal is required.\n");
WRITE ("\nType 'G' for a growth problem or 'D' for a decay problem ==> ");
READ (ans);
SkipLine;
IF ASCII.toUpper (ans) = "G" THEN
thisProblem := growth
ELSE
thisProblem := decay
END;

IF thisProblem = decay THEN
WRITE ("\nTo use half life, type an 'H'; to use decay constant, type 'K'==> ");
READ (ans);
SkipLine;
useHalfLife := ASCII.toUpper (ans) = "H";
END;

WRITE ("\nVery well, what is the ");
IF useHalfLife THEN
WRITE ("half life? ==> ");
ELSE
WRITE ("constant k (include sign if negative) ==> ");
END;
READ (k);
SkipLine;
IF useHalfLife THEN
k := (-1.0)*RealMath.ln(2.0)/k
END;

WRITE ("\nSo provide the original amount ==> ");
READ (initialAmount);
SkipLine;

REPEAT
WRITE ("\nProvide the elapsed time ==> ");
READ (time);
SkipLine;
finalAmount := initialAmount*RealMath.exp(k*time);
WRITE ("\nGiven a starting amount of ");
WRITEF ( "F.3", initialAmount);
WRITE (", the amount after ");
WRITEF ( "F.3", time);
WRITE (" time units will be ");
WRITEF ( "F.3", finalAmount);
WriteLn;
WRITE ("\nDo another changing only elapsed time? (Y/N) ==> ");
READ (doAgain);
SkipLine;
UNTIL ~doAgain;
WRITE ("\nExiting.\n");
END GrowthAndDecay.

Familiar points of interest:

Unlike many other languages, Modula-2 is strictly typed. This continues in R10, though we are more strict about typing. Note for instance that a real must be divided by 2.0, not by 2 (which is a whole type literal).

Modula-2 is case sensitive, and this continues in R10.

Modula-2 is modular. Most compilation units are either program modules or library modules. The latter have two parts--a definition, or interface, and an implementation. Program code can be compiled in the presence of the compiled definition modules, and the implementation of same done later, after the interface has been refined.

Library items are imported into other module either qualified (IMPORT modulename) or unqualified (FROM modulename IMPORT item). Examples here include the modules ASCII and RealMath, among others.

The very versatile IF--THEN..[ELSIF]*..ELSE..END construction, along with the original LOOP..EXIT..END, REPEAT..UNTIL, and WHILE..DO..END have been retained.

Comments are delineated with (* comment brackets *), may run over several lines, and may be nested.

Reserved words and standard identifiers are here presented in bold face, but this is merely for publication readability.

Changes and updates apparent here:

In Wirth's Modula-2 calls to NEW and DISPOSE were automatically translated into calls to ALLOCATE and DEALLOCATE, which had to be imported (generally from Storage.) We call these Wirthian macros, and have greatly expanded the utility of this idea.

Thus, READ, READNEW, WRITE, and WRITEF, along with several other standard procedure names, are Wirthian Macros. For instance, READ (item) is automatically translated into IO.Read (stdIn, item). In particular, READ (ans) becomes CharIO.Read (stdIn, ans).

stdIn must be made visible by being imported.

Any other File variable can be used instead of the defaults stdIn or stdOut.
The module IO support aggregates all the IO procedures from the .IO modules, and re-exports them so they can be imported qualified in bulk with a single satement.

A literal string may contain the escape sequence "\n", which outputs the OS-specific character(s) to generate a new line. This is the only such escape sequence.
WRITEF takes format strings and also defaults to the stdIn file. In the use shown here, "F.3" means generate a fixed point real numeral with three digits after the decimal.

All identifications and simple manipulations of characters (including change of case) are located in ASCII.

Changes not apparent here:

The FOR loop is now FOR [DESCENDING] variable IN type DO..END. The iteration type may be an index (indirect iteration) or the type of the items being processed (direct iteration).

All loops can have an EXIT statement.

Library modules are extensible. RealIO is an extension of the REAL type, for instance.

Programmers may create their own aggregator modules or extension modules.

The automatic compile-time binding of Wirthian macros by simple substitution effectively allows for a low-cost, simple form of overloading.

This binding can be performed for many operators, such as + - * / and structural elements such as FOR and []. However, arbitrary combinations of operators cannot be defined as new operators in the manner Apple has allowed in Swift, a practice we regard as opening a language up to abuse.

We have kept the list of reserved words and standard identifiers (the latter also reserved) deliberately small, in the same order as the original, not as the much larger ISO dialect. To do this, we dropped some features, such as local modules and the WITH statement and merged all the type conversion operators and syntax into a single notation.

A Run from this program:

In the Spy's latest novel, time is somewhat malleable, for two alternate earths have developed a time difference of 30 days. But time is running faster on the one that lags, so the difference is decaying with a half life of 78 days. To check on the difference after 263 days, the Spy ran his program, with the input and output as shown. The units are irrelevant, as long as they are consitent.

This program computes amounts of an exponentially growing or decaying population remaining after a specified time.

Note that when providing numerical answers, real format must be used--a decimal is required.

Type 'G' for a growth problem or 'D' for a decay problem ==> d

To use half life, type an 'H'; to use decay constant, type 'K'==> h

Very well, what is the half life? ==> 78.0

So provide the original amount ==> 30.0

Provide the elapsed time ==> 263.0

Given a starting amount of 30.000, the amount after 263.000 time units will be 2.898

Do another changing only elapsed time? (Y/N) ==> n

Exiting.

In the following months

The Spy will continue discussing some of the interesting points of Modula-2 R10, including extensibility, generics, blueprints, binding, and some of the standard library modules that are to be included with every R10 distribution. To forestall one group of questions, no, a compiler is not yet available. Programs here, and for the upcoming Springer-Verlag book, are compiled using boostrapped libraries atop older compilers, then have their syntax morphed into R10 style using macros.

--The Northern Spy

Opinions expressed here are entirely the author's own, and no endorsement is implied by any community or organization to which he may be attached. Rick Sutcliffe, (a. k. a. The Northern Spy) is professor of Computing Science and Mathematics at Canada's Trinity Western University. He has been involved as a member or consultant with the boards of several community and organizations, and participated in developing industry standards at the national and international level. He is a co-author of the Modula-2 programming language R10 dialect. He is a long time technology author and has written two textbooks and nine alternate history SF novels, one named best ePublished SF novel for 2003. His columns have appeared in numerous magazines and newspapers (paper and online), and he's a regular speaker at churches, schools, academic meetings, and conferences. He and his wife Joyce have lived in the Aldergrove/Bradner area of BC since 1972.

Want to discuss this and other Northern Spy columns? Surf on over to ArjayBB. com. Participate and you could win free web hosting from the WebNameHost. net subsidiary of Arjay Web Services. Rick Sutcliffe's fiction can be purchased in various eBook formats from Fictionwise, and in dead tree form from Amazon's Booksurge.

URLs for Rick Sutcliffe's Arjay Enterprises:

The Northern Spy Home Page: http: //www. TheNorthernSpy. com
opundo : http: //opundo. com
Sheaves Christian Resources : http: //sheaves. org
WebNameHost : http: //www. WebNameHost. net
WebNameSource : http: //www. WebNameSource. net
nameman : http: //nameman. net

General URLs for Rick Sutcliffe's Books:

Author Site: http: //www. arjay. ca
Publisher's Site: http: //www. writers-exchange. com/Richard-Sutcliffe. html
The Fourth Civilization--Ethics, Society, and Technology (4th 2003 ed. ): http: //www. arjay. bc. ca/EthTech/Text/index. html
Sites for Modula-2 resources
Modula-2 FAQ and ISO-based introductory text: http://www.modula-2.com
R10 Repository and source code: https://bitbucket.org/trijezdci/m2r10/src
More links, Wiki: http://www.modula-2.net
p1 ISO Modula-2 for the Mac: http://modula2.awiedemann.de/

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Six fantastic ways to spend National Vid...
As if anyone needed an excuse to play games today, I am about to give you one: it is National Video Games Day. A day for us to play games, like we no doubt do every day. Let’s not look a gift horse in the mouth. Instead, feast your eyes on this... | Read more »
Old School RuneScape players turn out in...
The sheer leap in technological advancements in our lifetime has been mind-blowing. We went from Commodore 64s to VR glasses in what feels like a heartbeat, but more importantly, the internet. It can be a dark mess, but it also brought hundreds of... | Read more »
Today's Best Mobile Game Discounts...
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links below... | Read more »
Nintendo and The Pokémon Company's...
Unless you have been living under a rock, you know that Nintendo has been locked in an epic battle with Pocketpair, creator of the obvious Pokémon rip-off Palworld. Nintendo often resorts to legal retaliation at the drop of a hat, but it seems this... | Read more »
Apple exclusive mobile games don’t make...
If you are a gamer on phones, no doubt you have been as distressed as I am on one huge sticking point: exclusivity. For years, Xbox and PlayStation have done battle, and before this was the Sega Genesis and the Nintendo NES. On console, it makes... | Read more »
Regionally exclusive events make no sens...
Last week, over on our sister site AppSpy, I babbled excitedly about the Pokémon GO Safari Days event. You can get nine Eevees with an explorer hat per day. Or, can you? Specifically, you, reader. Do you have the time or funds to possibly fly for... | Read more »
As Jon Bellamy defends his choice to can...
Back in March, Jagex announced the appointment of a new CEO, Jon Bellamy. Mr Bellamy then decided to almost immediately paint a huge target on his back by cancelling the Runescapes Pride event. This led to widespread condemnation about his perceived... | Read more »
Marvel Contest of Champions adds two mor...
When I saw the latest two Marvel Contest of Champions characters, I scoffed. Mr Knight and Silver Samurai, thought I, they are running out of good choices. Then I realised no, I was being far too cynical. This is one of the things that games do best... | Read more »
Grass is green, and water is wet: Pokémo...
It must be a day that ends in Y, because Pokémon Trading Card Game Pocket has kicked off its Zoroark Drop Event. Here you can get a promo version of another card, and look forward to the next Wonder Pick Event and the next Mass Outbreak that will be... | Read more »
Enter the Gungeon review
It took me a minute to get around to reviewing this game for a couple of very good reasons. The first is that Enter the Gungeon's style of roguelike bullet-hell action is teetering on the edge of being straight-up malicious, which made getting... | Read more »

Price Scanner via MacPrices.net

Take $150 off every Apple 11-inch M3 iPad Air
Amazon is offering a $150 discount on 11-inch M3 WiFi iPad Airs right now. Shipping is free: – 11″ 128GB M3 WiFi iPad Air: $449, $150 off – 11″ 256GB M3 WiFi iPad Air: $549, $150 off – 11″ 512GB M3... Read more
Apple iPad minis back on sale for $100 off MS...
Amazon is offering $100 discounts (up to 20% off) on Apple’s newest 2024 WiFi iPad minis, each with free shipping. These are the lowest prices available for new minis among the Apple retailers we... Read more
Apple’s 16-inch M4 Max MacBook Pros are on sa...
Amazon has 16-inch M4 Max MacBook Pros (Silver and Black colors) on sale for up to $410 off Apple’s MSRP right now. Shipping is free. Be sure to select Amazon as the seller, rather than a third-party... Read more
Red Pocket Mobile is offering a $150 rebate o...
Red Pocket Mobile has new Apple iPhone 17’s on sale for $150 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more
Switch to Verizon, and get any iPhone 16 for...
With yesterday’s introduction of the new iPhone 17 models, Verizon responded by running “on us” promos across much of the iPhone 16 lineup: iPhone 16 and 16 Plus show as $0/mo for 36 months with bill... Read more
Here is a summary of the new features in Appl...
Apple’s September 2025 event introduced major updates across its most popular product lines, focusing on health, performance, and design breakthroughs. The AirPods Pro 3 now feature best-in-class... Read more
Apple’s Smartphone Lineup Could Use A Touch o...
COMMENTARY – Whatever happened to the old adage, “less is more”? Apple’s smartphone lineup. — which is due for its annual refresh either this month or next (possibly at an Apple Event on September 9... Read more
Take $50 off every 11th-generation A16 WiFi i...
Amazon has Apple’s 11th-generation A16 WiFi iPads in stock on sale for $50 off MSRP right now. Shipping is free: – 11″ 11th-generation 128GB WiFi iPads: $299 $50 off MSRP – 11″ 11th-generation 256GB... Read more
Sunday Sale: 14-inch M4 MacBook Pros for up t...
Don’t pay full price! Amazon has Apple’s 14-inch M4 MacBook Pros (Silver and Black colors) on sale for up to $220 off MSRP right now. Shipping is free. Be sure to select Amazon as the seller, rather... Read more
Mac mini with M4 Pro CPU back on sale for $12...
B&H Photo has Apple’s Mac mini with the M4 Pro CPU back on sale for $1259, $140 off MSRP. B&H offers free 1-2 day shipping to most US addresses: – Mac mini M4 Pro CPU (24GB/512GB): $1259, $... Read more

Jobs Board

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.