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

Tokkun Studio unveils alpha trailer for...
We are back on the MMORPG news train, and this time it comes from the sort of international developers Tokkun Studio. They are based in France and Japan, so it counts. Anyway, semantics aside, they have released an alpha trailer for the upcoming... | Read more »
Win a host of exclusive in-game Honor of...
To celebrate its latest Jujutsu Kaisen crossover event, Honor of Kings is offering a bounty of login and achievement rewards kicking off the holiday season early. [Read more] | Read more »
Miraibo GO comes out swinging hard as it...
Having just launched what feels like yesterday, Dreamcube Studio is wasting no time adding events to their open-world survival Miraibo GO. Abyssal Souls arrives relatively in time for the spooky season and brings with it horrifying new partners to... | Read more »
Ditch the heavy binders and high price t...
As fun as the real-world equivalent and the very old Game Boy version are, the Pokemon Trading Card games have historically been received poorly on mobile. It is a very strange and confusing trend, but one that The Pokemon Company is determined to... | Read more »
Peace amongst mobile gamers is now shatt...
Some of the crazy folk tales from gaming have undoubtedly come from the EVE universe. Stories of spying, betrayal, and epic battles have entered history, and now the franchise expands as CCP Games launches EVE Galaxy Conquest, a free-to-play 4x... | Read more »
Lord of Nazarick, the turn-based RPG bas...
Crunchyroll and A PLUS JAPAN have just confirmed that Lord of Nazarick, their turn-based RPG based on the popular OVERLORD anime, is now available for iOS and Android. Starting today at 2PM CET, fans can download the game from Google Play and the... | Read more »
Digital Extremes' recent Devstream...
If you are anything like me you are impatiently waiting for Warframe: 1999 whilst simultaneously cursing the fact Excalibur Prime is permanently Vault locked. To keep us fed during our wait, Digital Extremes hosted a Double Devstream to dish out a... | Read more »
The Frozen Canvas adds a splash of colou...
It is time to grab your gloves and layer up, as Torchlight: Infinite is diving into the frozen tundra in its sixth season. The Frozen Canvas is a colourful new update that brings a stylish flair to the Netherrealm and puts creativity in the... | Read more »
Back When AOL WAS the Internet – The Tou...
In Episode 606 of The TouchArcade Show we kick things off talking about my plans for this weekend, which has resulted in this week’s show being a bit shorter than normal. We also go over some more updates on our Patreon situation, which has been... | Read more »
Creative Assembly's latest mobile p...
The Total War series has been slowly trickling onto mobile, which is a fantastic thing because most, if not all, of them are incredibly great fun. Creative Assembly's latest to get the Feral Interactive treatment into portable form is Total War:... | Read more »

Price Scanner via MacPrices.net

Early Black Friday Deal: Apple’s newly upgrad...
Amazon has Apple 13″ MacBook Airs with M2 CPUs and 16GB of RAM on early Black Friday sale for $200 off MSRP, only $799. Their prices are the lowest currently available for these newly upgraded 13″ M2... Read more
13-inch 8GB M2 MacBook Airs for $749, $250 of...
Best Buy has Apple 13″ MacBook Airs with M2 CPUs and 8GB of RAM in stock and on sale on their online store for $250 off MSRP. Prices start at $749. Their prices are the lowest currently available for... Read more
Amazon is offering an early Black Friday $100...
Amazon is offering early Black Friday discounts on Apple’s new 2024 WiFi iPad minis ranging up to $100 off MSRP, each with free shipping. These are the lowest prices available for new minis anywhere... Read more
Price Drop! Clearance 14-inch M3 MacBook Pros...
Best Buy is offering a $500 discount on clearance 14″ M3 MacBook Pros on their online store this week with prices available starting at only $1099. Prices valid for online orders only, in-store... Read more
Apple AirPods Pro with USB-C on early Black F...
A couple of Apple retailers are offering $70 (28%) discounts on Apple’s AirPods Pro with USB-C (and hearing aid capabilities) this weekend. These are early AirPods Black Friday discounts if you’re... Read more
Price drop! 13-inch M3 MacBook Airs now avail...
With yesterday’s across-the-board MacBook Air upgrade to 16GB of RAM standard, Apple has dropped prices on clearance 13″ 8GB M3 MacBook Airs, Certified Refurbished, to a new low starting at only $829... Read more
Price drop! Apple 15-inch M3 MacBook Airs now...
With yesterday’s release of 15-inch M3 MacBook Airs with 16GB of RAM standard, Apple has dropped prices on clearance Certified Refurbished 15″ 8GB M3 MacBook Airs to a new low starting at only $999.... Read more
Apple has clearance 15-inch M2 MacBook Airs a...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs now available starting at $929 and ranging up to $410 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at... Read more
Apple drops prices on 13-inch M2 MacBook Airs...
Apple has dropped prices on 13″ M2 MacBook Airs to a new low of only $749 in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, now available for $679 for 8-Core CPU/7-Core GPU/256GB models. Apple’s one-year warranty is included, shipping is free, and each... Read more

Jobs Board

Seasonal Cashier - *Apple* Blossom Mall - J...
Seasonal Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Seasonal Fine Jewelry Commission Associate -...
…Fine Jewelry Commission Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) Read more
Seasonal Operations Associate - *Apple* Blo...
Seasonal Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Read more
Hair Stylist - *Apple* Blossom Mall - JCPen...
Hair Stylist - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.