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

Top 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... | Read more »
Price of Glory unleashes its 1.4 Alpha u...
As much as we all probably dislike Maths as a subject, we do have to hand it to geometry for giving us the good old Hexgrid, home of some of the best strategy games. One such example, Price of Glory, has dropped its 1.4 Alpha update, stocked full... | Read more »
The SLC 2025 kicks off this month to cro...
Ever since the Solo Leveling: Arise Championship 2025 was announced, I have been looking forward to it. The promotional clip they released a month or two back showed crowds going absolutely nuts for the previous competitions, so imagine the... | Read more »
Dive into some early Magicpunk fun as Cr...
Excellent news for fans of steampunk and magic; the Precursor Test for Magicpunk MMORPG Crystal of Atlan opens today. This rather fancy way of saying beta test will remain open until March 5th and is available for PC - boo - and Android devices -... | Read more »
Prepare to get your mind melted as Evang...
If you are a fan of sci-fi shooters and incredibly weird, mind-bending anime series, then you are in for a treat, as Goddess of Victory: Nikke is gearing up for its second collaboration with Evangelion. We were also treated to an upcoming... | Read more »
Square Enix gives with one hand and slap...
We have something of a mixed bag coming over from Square Enix HQ today. Two of their mobile games are revelling in life with new events keeping them alive, whilst another has been thrown onto the ever-growing discard pile Square is building. I... | Read more »
Let the world burn as you have some fest...
It is time to leave the world burning once again as you take a much-needed break from that whole “hero” lark and enjoy some celebrations in Genshin Impact. Version 5.4, Moonlight Amidst Dreams, will see you in Inazuma to attend the Mikawa Flower... | Read more »
Full Moon Over the Abyssal Sea lands on...
Aether Gazer has announced its latest major update, and it is one of the loveliest event names I have ever heard. Full Moon Over the Abyssal Sea is an amazing name, and it comes loaded with two side stories, a new S-grade Modifier, and some fancy... | Read more »
Open your own eatery for all the forest...
Very important question; when you read the title Zoo Restaurant, do you also immediately think of running a restaurant in which you cook Zoo animals as the course? I will just assume yes. Anyway, come June 23rd we will all be able to start up our... | Read more »
Crystal of Atlan opens registration for...
Nuverse was prominently featured in the last month for all the wrong reasons with the USA TikTok debacle, but now it is putting all that behind it and preparing for the Crystal of Atlan beta test. Taking place between February 18th and March 5th,... | Read more »

Price Scanner via MacPrices.net

AT&T is offering a 65% discount on the ne...
AT&T is offering the new iPhone 16e for up to 65% off their monthly finance fee with 36-months of service. No trade-in is required. Discount is applied via monthly bill credits over the 36 month... Read more
Use this code to get a free iPhone 13 at Visi...
For a limited time, use code SWEETDEAL to get a free 128GB iPhone 13 Visible, Verizon’s low-cost wireless cell service, Visible. Deal is valid when you purchase the Visible+ annual plan. Free... Read more
M4 Mac minis on sale for $50-$80 off MSRP at...
B&H Photo has M4 Mac minis in stock and on sale right now for $50 to $80 off Apple’s MSRP, each including free 1-2 day shipping to most US addresses: – M4 Mac mini (16GB/256GB): $549, $50 off... Read more
Buy an iPhone 16 at Boost Mobile and get one...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering one year of free Unlimited service with the purchase of any iPhone 16. Purchase the iPhone at standard MSRP, and then choose... Read more
Get an iPhone 15 for only $299 at Boost Mobil...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering the 128GB iPhone 15 for $299.99 including service with their Unlimited Premium plan (50GB of premium data, $60/month), or $20... Read more
Unreal Mobile is offering $100 off any new iP...
Unreal Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering a $100 discount on any new iPhone with service. This includes new iPhone 16 models as well as iPhone 15, 14, 13, and SE... Read more
Apple drops prices on clearance iPhone 14 mod...
With today’s introduction of the new iPhone 16e, Apple has discontinued the iPhone 14, 14 Pro, and SE. In response, Apple has dropped prices on unlocked, Certified Refurbished, iPhone 14 models to a... Read more
B&H has 16-inch M4 Max MacBook Pros on sa...
B&H Photo is offering a $360-$410 discount on new 16-inch MacBook Pros with M4 Max CPUs right now. B&H offers free 1-2 day shipping to most US addresses: – 16″ M4 Max MacBook Pro (36GB/1TB/... Read more
Amazon is offering a $100 discount on the M4...
Amazon has the M4 Pro Mac mini discounted $100 off MSRP right now. Shipping is free. Their price is the lowest currently available for this popular mini: – Mac mini M4 Pro (24GB/512GB): $1299, $100... Read more
B&H continues to offer $150-$220 discount...
B&H Photo has 14-inch M4 MacBook Pros on sale for $150-$220 off MSRP. B&H offers free 1-2 day shipping to most US addresses: – 14″ M4 MacBook Pro (16GB/512GB): $1449, $150 off MSRP – 14″ M4... Read more

Jobs Board

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