Modula 3 intro
#1021
Replies: 3 comments 3 replies
-
This looks very good. No substantive suggestions, but two very minor bikeshedding,
spelling things. Niklaus Wirth and Trestle.
^ ^
Glad to hear of some uses of Trestle, FormsVBT, etc.
Keep up the good work.
…On 4/1/22 05:02, MarcusE1W wrote:
Hi.
I have written this as an introduction into Modula 3 for the Pinebook Pro forum <https://forum.pine64.org/forumdisplay.php?fid=111>.
As I am new to Module 3 I was wondering if people here could have one look and let me know any suggestions.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Modula 3 on the Pinebook
Installation
Modula 3 is a programming language based on Pascal and Modula 2 from Niklas Wirth. Modula 3 has been developed in ~1992 by DEC with the blessing of Mr. Wirth.
Modula 3 is strongly typed, has a powerful module system and has generics, OO additions as well as build in support for concurrent programming. The additions to the language add some comport to programming. Here <XXX> is an overview of the main differences between Modula 3 and Modula 2.
It also seems to be an historic oversight that the multi platform GUI library Tristle has not become more well known and popular.
The Tristle multi-platform GUI library from beginning of the 90th allows you to write Modula 3 programmes for X11 and Windows (Win32) with the same code and it all still works. In 1994 that was almost unique. Well worth to explore a bit.
There is an up-to-date Modula 3 compiler that installs and runs well on the Pinebook with Manjaro: CM3 <https://github.com/modula3/cm3>
A good install guide is in the Wiki <https://github.com/modula3/cm3/wiki/Getting-Started:-Linux>
The steps to install on Manjaro are:
|sudo pacman -S base-devel cmake sudo pacman -S glu mesa xorg-server-devel git clone https://github.com/modula3/cm3 cm3-git mkdir build cd build ../cm3-git/scripts/concierge.py install --prefix $HOME/cm3 all --target ARM64_LINUX |
Notes for the install process:
* The final install folder is called |cm3|, that's why the git folder is called |cm3-git| to keep things separate
* You probably don't have to install all prerequisites. Some are installed already
* the |build| folder is created on the same level as the |cm3-git| folder
The compile process takes some time on the Pinebook Pro. This is probably a good opportunity to have a look at some of the highlights of the documentation:
* Modula 3 web site <http://modula3.github.io/cm3/>
* A good overview of the language can be found here <http://modula3.github.io/cm3/tutorial/m3/m3_toc.html>. More a reference with examples than a tutorial.
* Overview of the Standard Library <http://modula3.github.io/cm3/help/interfaces.html>. Modula 3 is very module oriented, so this is a good start.
* The highlight for me is the GUI library Tristle <http://modula3.github.io/cm3/src_reports/src-069.pdf>. (Some makefiles in this document are in an older version and need small updates like "" added for names.)
The highlight for me is definitely the GUI library Tristle. Works perfect on Manjaro with X11. I have not tested it on Windows, but apparently that works as well. For an 30 years old library that is truly remarkable.
Have I mentioned the WYSIWYG GUI design app FormsVBT <http://modula3.github.io/cm3/src_reports/formsvbt.pdf> already ?
formsedit <https://camo.githubusercontent.com/92c9661661376bb865c85ccf613fee8c225b8fcf4854aff425cfc55c6b303667/68747470733a2f2f692e706f7374696d672e63632f5a306b77745358582f466f726d735642542e706e67>
So, now the install should be completed. The compiler has been installed in |~/cm3|
Add this bin folder to the PATH |export PATH="$HOME/cm3/bin:$PATH"|
Starting with Modula 3
Example 1: Hello World
Before the example here is the first m3makefile. Some help for the m3mankefile is here <http://modula3.github.io/cm3/tutorial/m3/m3_3.html#SEC3>. For a small example it is not strictly necessary but this is how Modula 3 ticks so let's just use it:
Create a folder |example|
Create a subfolder |example/src|
Create the makefile |example/src/m3makefile|
Create the Modula 3 example |example/src/Hello.m3|
m3makefile
|% HelloTrestle import ( "ui") implementation ("Hello") program ("Hello") |
Hello.m3
|MODULE Hello EXPORTS Main; IMPORT TextVBT, Trestle; VAR v := TextVBT.New("Hello Trestle on Pinebook"); BEGIN Trestle.Install(v); Trestle.AwaitDelete(v) END Hello. |
In folder |example| use the command |cm3| and the programme will be compiled.
The result is in |ARM64_LINUX/|. Start the example with |./ARM64_LINUX/Hello|.
You get a nice little Window with a Hello message.
Hello window <https://camo.githubusercontent.com/79bf70fa026821dbda1d1e85c75f4051be563a56abccdde8c8f54f14918d3e3d/68747470733a2f2f692e706f7374696d672e63632f58716363424372372f48656c6c6f2e706e67>
If you compare the m3makefile to some documentation you will also notice how to update some of the older m3makefiles mentioned there. Often additional "" are needed.
Example 2: Module concept
Modula 3 has it's name from the module concept. Her is how it works:
Every module has an interface definition in a file with |.i3| ending. The implementation is in a file with |.m3| ending.
Create another folder |example2|
Create |example2/src|
Place all files into the |src/| folder:
The Interface description looks like this: |A.i3|
|INTERFACE A; PROCEDURE DoIt(); END A. |
Here is the implementation of the interface: |A.m3|:
|MODULE A; IMPORT IO; PROCEDURE DoIt() = BEGIN IO.Put("Hello World\n"); END DoIt; BEGIN END A. |
And the main programe: |Example2.m3|:
|MODULE Example2 EXPORTS Main; IMPORT A; BEGIN A.DoIt(); END Example2. |
All brought together with the |m3makefile|
|import ("libm3") implementation ("Example2") module ("A") program ("test2") |
Although some of the source material and documentation is old it still works nicely and Modula 3 is even by today's standards a very useful, flexible and pleasant language.
The kink with the capitalised KEYWORDS is sorted in the editor, e.g. Emacs <https://github.com/modula3/cm3/tree/master/m3-tools/gnuemacs/src> or VSCode. You don't need to actually types like that but it makes the structure of the source code very clear and readable.
—
Reply to this email directly, view it on GitHub <#1021>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABSVZNHGQSRWXH5O4PPZDXDVC3CSHANCNFSM5SIF3XZA>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
-
Ah, Jay...
I agree it is "Modula-3".
But... I'd write, "Optionally unsafe", "optionally self-managed memory"...
the clear design intent of the language is to be "almost always" safe &
garbage collected! I think your views are a bit skewed since you work a
lot in the twilight-zone interface world between M3, the OS, and C
bindings. My experience is that if you actually write a lot of application
code in M3, you almost never resort to using the keyword "UNSAFE". Yeah
you can sometimes get some more performance by using it, but even without
it, I think you tend to do a lot better than Java in most cases.
Mika
…On Tue, Apr 19, 2022 at 3:55 AM Jay Krell ***@***.***> wrote:
"Modula 3" can you remove the space or maybe put in a dash?
Optionally safe. Optionally garbage collected. Always compiles to native.
Never JITed. Has generics. Has a decent builtin build system. And very
portable by virtue of targeting C++ and Posix or Windows. And written in
itself. :)
—
Reply to this email directly, view it on GitHub
<#1021 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABKYNJIW7KOXIQ5ADZNBUOLVF2GJVANCNFSM5SIF3XZA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
2 replies
-
I'm not disagreeing with you!
Just proposing a change in emphasis. "Optionally unsafe" rather than
"Optionally safe".
Why are you wary of garbage collectors?
…On Wed, Apr 20, 2022 at 12:15 AM Jay Krell ***@***.***> wrote:
But optionally safe is much better than safe. Always safe languages cannot
be written in themselves.
Optionally safe is historically rare. Compiled to native is historically
rare. They are less rare these days: .Net.Native, Rust, and Go, share these
characteristics. Java, Ruby, Python, Perl, C++, do not.
—
Reply to this email directly, view it on GitHub
<#1021 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABKYNJOOEY6WAYP2JD7LXM3VF6VIVANCNFSM5SIF3XZA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
20/04: Updated from comment below
Hi.
I have written this as an introduction into Modula-3 for the Pinebook Pro forum.
As I am new to Module 3 I was wondering if people here could have one look and let me know any suggestions.
Modula-3 on the Pinebook
Installation
Modula-3 is a programming language based on Pascal and Modula 2 from Niklaus Wirth. Modula-3 has been developed in ~1992 by DEC with the blessing of Mr. Wirth.
Modula-3 is strongly typed, has a powerful module system and has generics, OO additions as well as build in support for concurrent programming. The additions to the language add some comport to programming. Here is an overview of the main differences between Modula-3 and Modula 2.
It also seems to be an historic oversight that the multi platform GUI library Trestle has not become more well known and popular.
There is an up-to-date Modula-3 compiler that installs and runs well on the Pinebook with Manjaro: CM3
A good install guide is in the Wiki
The steps to install on Manjaro are:
Notes for the install process:
cm3
, that's why the git folder is calledcm3-git
to keep things separatebuild
folder is created on the same level as thecm3-git
folderThe compile process takes some time on the Pinebook Pro. This is probably a good opportunity to have a look at some of the highlights of the documentation:
The highlight for me is definitely the GUI library Trestle. Works perfect on Manjaro with X11. I have not tested it on Windows, but apparently that works as well. For an 30 years old library that is truly remarkable.
Have I mentioned the WYSIWYG GUI design app FormsVBT already ?
So, now the install should be completed. The compiler has been installed in
~/cm3
Add this bin folder to the PATH
export PATH="$HOME/cm3/bin:$PATH"
Starting with Modula-3
Example 1: Hello World
Before the example here is the first m3makefile. Some help for the m3mankefile is here. For a small example it is not strictly necessary but this is how Modula-3 ticks so let's just use it:
m3makefile
Hello.m3
In folder
example
use the commandcm3
and the programme will be compiled.The result is in
ARM64_LINUX/
. Start the example with./ARM64_LINUX/Hello
.You get a nice little Window with a Hello message.
If you compare the m3makefile to some documentation you will also notice how to update some of the older m3makefiles mentioned there. Often additional "" are needed.
Example 2: Module concept
Modula-3 has it's name from the module concept. Her is how it works:
Every module has an interface definition in a file with
.i3
ending. The implementation is in a file with.m3
ending.Place all files into the
src/
folder:The Interface description looks like this:
A.i3
Here is the implementation of the interface:
A.m3
:And the main programe:
Example2.m3
:All brought together with the
m3makefile
Although some of the source material and documentation is old it still works nicely and Modula-3 is even by today's standards a very useful, flexible and pleasant language.
Key characteristics:
The kink with the capitalised KEYWORDS is sorted in the editor, e.g. Emacs or VSCode. You don't need to actually types like that but it makes the structure of the source code very clear and readable.
Beta Was this translation helpful? Give feedback.
All reactions