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

Watcher of Realms unveils new story and...
Watcher of Realms players are in for quite the feast this month, as Moonton release two powerful new heroes, including one that will burst down even the most mighty of foes. Recruit your new friends, and then burn through the Main Quest expansion... | Read more »
Reverse: 1999 continues its trip down un...
The field trip to Australia continues in Reverse: 1999 as Phase 2 of Revival! The Uluru Games kicks off. You will be able to collect new characters, engage with new events, get hordes of free gifts, and follow the story of a mushroom-based... | Read more »
Ride into the zombie apocalypse in style...
Back in the good old days of Flash games, there were a few staples; Happy Wheels, Stick RPG, and of course the apocalyptic driver Earn to Die. Fans of the running over zombies simulator can rejoice, as the sequel to the legendary game, Earn to Die... | Read more »
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 below... | Read more »
Netflix Games expands its catalogue with...
It is a good time to be a Netflix subscriber this month. I presume there's a good show or two, but we are, of course, talking about their gaming service that seems to be picking up steam lately. May is adding five new titles, and there are some... | Read more »
Pokemon Go takes a step closer to real P...
When Pokemon Go was first announced, one of the best concepts of the whole thing was having your favourite Pokemon follow you in the real world and be able to interact with them. To be frank, the AR Snapshot tool could have done a lot more to help... | Read more »
Seven Knights Idle Adventure drafts in a...
Seven Knights Idle Adventure is opening up more stages, passing the 15k mark, and players may find themselves in need of more help to clear these higher stages. Well, the cavalry has arrived with the introduction of the Legendary Hero Iris, as... | Read more »
AFK Arena celebrates five years of 100 m...
Lilith Games is quite the behemoth when it comes to mobile games, with Rise of Kingdom and Dislyte firmly planting them as a bit name. Also up there is AFK Arena, which is celebrating a double whammy of its 5th anniversary, as well as blazing past... | Read more »
Fallout Shelter pulls in ten times its u...
When the Fallout TV series was announced I, like I assume many others, assumed it was going to be an utter pile of garbage. Well, as we now know that couldn't be further from the truth. It was a smash hit, and this success has of course given the... | Read more »
Recruit two powerful-sounding students t...
I am a fan of anime, and I hear about a lot that comes through, but one that escaped my attention until now is A Certain Scientific Railgun T, and that name is very enticing. If it's new to you too, then players of Blue Archive can get a hands-on... | Read more »

Price Scanner via MacPrices.net

13-inch M3 MacBook Airs on sale starting at $...
Amazon has every configuration and color of Apple’s 13″ M3 MacBook Air on sale for $150 off MSRP, now starting at $949 shipped. Their prices are the lowest available for these Airs among Apple’s... Read more
14-inch M3 Pro/Max MacBook Pro available toda...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
Apple has the Apple Watch Ultra available for...
Apple has several Certified Refurbished Apple Watch Ultra models available in their online store for $589, or $210 off original MSRP. Each Watch includes Apple’s standard one-year warranty, a new... Read more
M2 Mac minis on sale starting at only $449
B&H Photo has M2-powered Mac minis in stock and on sale today for $100 off Apple’s MSRP. Free 1-2 day shipping is available for most US addresses: – Mac mini M2/256GB SSD: $499, save $100 – Mac... Read more
Retailers are clearing out 9th-generation iPa...
With the introduction of new iPad Air and iPad Pros, along with newly discounted 10th-generation iPads, several Apple retailers are clearing out their remaining stock of 9th-generation iPads. Prices... Read more
Apple Studio Display with Standard Glass on s...
Best Buy has the standard-glass Apple Studio Display on sale for $300 off MSRP for a limited time. Their price is the lowest available for a Studio Display among Apple’s retailers. Shipping is free... Read more
AirPods Max headphones back on sale for $449,...
Amazon has Apple AirPods Max headphones in stock and on sale for $100 off MSRP, only $449. The sale price is valid for all colors at the time of this post. Shipping is free: – AirPods Max: $449.99 $... Read more
Deal Alert! 13-inch M2 MacBook Airs on record...
Amazon has 13″ MacBook Airs with M2 CPUs in stock and on sale this week for only $829 in Space Gray, Silver, Starlight, and Midnight colors. Their price is $170 off Apple’s MSRP, and it’s the lowest... Read more
Apple Watch Ultra 2 on sale for $50 off MSRP
Best Buy is offering Apple Watch Ultra 2 models for $50 off MSRP on their online store this week. Sale prices available for online orders only, in-store prices may vary. Order online, and choose free... Read more
Apple introduces the new M4-powered 11-inch a...
Today, Apple revealed the new 2024 M4 iPad Pro series, boasting a surprisingly thin and light design that pushes the boundaries of portability and performance. Offered in silver and space black... Read more

Jobs Board

Early Preschool Teacher - Glenda Drive/ *Appl...
Early Preschool Teacher - Glenda Drive/ Apple ValleyTeacher Share by Email Share on LinkedIn Share on Twitter Read more
Senior Software Engineer - *Apple* Fundamen...
…center of Microsoft's efforts to empower our users to do more. The Apple Fundamentals team focused on defining and improving the end-to-end developer experience in Read more
*Apple* Systems Administrator - JAMF - Activ...
…**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
Relationship Banker *Apple* Valley Main - W...
…Alcohol Policy to learn more. **Company:** WELLS FARGO BANK **Req Number:** R-367184 **Updated:** Wed May 08 00:00:00 UTC 2024 **Location:** APPLE VALLEY,California Read more
Rehabilitation Technician - *Apple* Hill (O...
Rehabilitation Technician - Apple Hill (Outpatient Clinic) - PRN Location: York Hospital, York, PA Schedule: PRN/Per Diem Sign-On Bonus Eligible Remote/Hybrid Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.