Oberon Community Platform Forum

Development => Oberon & Active Oberon => Topic started by: dukester on July 31, 2010, 08:52:41 PM



Title: Need help with this code
Post by: dukester on July 31, 2010, 08:52:41 PM
Hello list:

Need help with this code, please:

Code:
MODULE QtrMile;
IMPORT Out IN Oberon;
VAR mi,qmi,cm,inch,ft,yd,m:REAL;
BEGIN
cm:=1.0;
m:=100*cm;
inch:=2.54*cm;
ft:=12*inch;
yd:=3*ft;
mi:=5280*ft;
qmi:=mi/4.0;

Out.String('A quarter mile is equal to:');Out.Ln;
Out.LongRealFix(qmi/m,20,6);Out.String(' meters');Out.Ln;
Out.LongRealFix(qmi/yd,20,6);Out.String(' yards');Out.Ln;
END QtrMile.

SystemTools.Free QtrMile~

QtrMile~

The above is code that I ported from oo2c. It compiles cleanly in A2, but when I execute it ( by clicking with my MouseWheel

 on the previous line) I get:


Quote
WMTextView: Command parsing error, res: 3903 (Expected ModuleName "." [ProcedureName])

Do I absolutely need to use at least one procedure in an Oberon module? I have yet to read that anywhere ;)

As well, all critique of coding style, etc, etc would be welcome and appreciated!



Title: Re: Need help with this code
Post by: Bernhard T. on July 31, 2010, 10:36:57 PM
Try:

Code:
MODULE QtrMile;
IMPORT Out IN Oberon;
VAR mi,qmi,cm,inch,ft,yd,m:REAL;

PROCEDURE Do*;
BEGIN END Do;

BEGIN
cm:=1.0; m:=100*cm;
inch:=2.54*cm; ft:=12*inch;
yd:=3*ft; mi:=5280*ft;
qmi:=mi/4.0;

Out.String('A quarter mile is equal to:');Out.Ln;
Out.LongRealFix(qmi/m,20,6);Out.String(' meters');Out.Ln;
Out.LongRealFix(qmi/yd,20,6);Out.String(' yards');Out.Ln;
END QtrMile.

You can click on QtrMile.Do ~

AFAIK, the "command interpreter" wants a command, ie.: SomeModule.SomeProcedure ...

The concept of commands is unknown to OOC.

PS: In this way it will work only once until you unload.

Bernhard


Title: Re: Need help with this code
Post by: dukester on July 31, 2010, 11:42:45 PM
I see!

So the moral of the story is that in "true" Oberon,  ;D ,  a procedure - even an empty one - must be used in the "command". Am I correct?

What about my coding style? Is it OK?



Title: Re: Need help with this code
Post by: soren renner on August 01, 2010, 04:56:26 PM
Looks all right to me.


Title: Re: Need help with this code
Post by: dukester on August 01, 2010, 07:25:01 PM
Cool! TTYL...


Title: Re: Need help with this code
Post by: staubesv on August 02, 2010, 08:59:00 AM
To load a module without executing a command offered by the module, either...


... middle click on ModuleName + "."  (dot is required, module will be loaded but an error message about the command not being found appears)

or

... SystemTools.Load ModuleName ~


Title: Re: Need help with this code
Post by: dukester on August 02, 2010, 02:21:17 PM
To load a module without executing a command offered by the module, either...


... middle click on ModuleName + "."  (dot is required, module will be loaded but an error message about the command not being found appears)

or

... SystemTools.Load ModuleName ~

So this will load _and_ execute the "body" of a MODULE without actually calling a particular procedure within that same MODULE?


Title: Re: Need help with this code
Post by: staubesv on August 02, 2010, 02:38:33 PM
Quote
So this will load _and_ execute the "body" of a MODULE without actually calling a particular procedure within that same MODULE?
Yes.


Title: Re: Need help with this code
Post by: dukester on August 02, 2010, 05:05:48 PM
Quote
So this will load _and_ execute the "body" of a MODULE without actually calling a particular procedure within that same MODULE?
Yes.

Excellent! Thank you...


Title: Re: Need help with this code
Post by: dukester on August 05, 2010, 03:06:39 PM
Quote
So this will load _and_ execute the "body" of a MODULE without actually calling a particular procedure within that same MODULE?
Yes.

Update:  It doesn't seem to work....

So, according to what you said on another thread, PACO is suppose to be a superset of OP2, correct?

Here's the code:
Code:
MODULE QtrMile;
         IMPORT Out IN Oberon;
         VAR mi,qmi,cm,inch,ft,yd,m:REAL;
BEGIN
         cm:=1.0;
         m:=100*cm;
         inch:=2.54*cm;
         ft:=12*inch;
         yd:=3*ft;
         mi:=5280*ft;
         qmi:=mi/4.0;

         Out.String('A quarter mile is equal to:');Out.Ln;
         Out.LongRealFix(qmi/m,20,6);Out.String(' meters');Out.Ln;
         Out.LongRealFix(qmi/yd,20,6);Out.String(' yards');Out.Ln;
END QtrMile.

SystemTools.Free QtrMile ~

QtrMile. ~

When I middle-click on  QtrMile. ~
PET hangs. The Log Viewer shows the pid etc for the process, and nothing else. I then have to go to Inspect/Objects to kill the appropriate pid. When I do that, Trap emerges with a lot of feedback about "Oberon" something or other.

Try it out! AFAIK, the code is just simple Oberon-2 stuff.

Now if OP2 in Native Oberon on A2 was not broken, then I could fire up Tools/Oberon and go play there ;)


Title: Re: Need help with this code
Post by: masta on August 06, 2010, 06:54:28 AM
Habe das mal gestrippt auf
Out.Ln;

Dass PET haengt (auf UnixAos) kann ich reproduzieren.
Wenn allerdings eine Procedure do eingebaut wird, dann mit QtrMile.do ~ Modul geladen, so trapt es in und im log erscheint die Meldung
Quote
Oberon has been called from an outside process. Don't do that.
Das ist as simple as possible. Don't make it simpler.

Wie staubers schon gesagt hat: Oberon ist Sprache und Laufzeitumgebung. Ausserhalb von Oberon als Laufzeitumgebung ist eine der zwei Modulvariablen von Oberon.Out nicht initialisiert. Wenn Out.Ln nicht aufgerufen wird, so läuft QtrMile.do ~.



Title: Re: Need help with this code
Post by: staubesv on August 06, 2010, 08:24:18 AM
Quote
Try it out! AFAIK, the code is just simple Oberon-2 stuff.
This isn't Oberon-2 stuff, it's Native Oberon stuff. The module Out is written in the programming language Oberon-2 but it is supposed to run with the Native Oberon operating system (the module Out uses Native Oberon API's)!
That's what I meant: You can write Oberon-2 programs using PACO, but you cannot use Native Oberon API's in A2. You can, however, run your program compiled with PACO under Oberon (under A2).


Title: Re: Need help with this code
Post by: dukester on August 06, 2010, 03:21:19 PM
Quote
Try it out! AFAIK, the code is just simple Oberon-2 stuff.
This isn't Oberon-2 stuff, it's Native Oberon stuff. The module Out is written in the programming language Oberon-2 but it is supposed to run with the Native Oberon operating system (the module Out uses Native Oberon API's)!
That's what I meant: You can write Oberon-2 programs using PACO, but you cannot use Native Oberon API's in A2. You can, however, run your program compiled with PACO under Oberon (under A2).

So the compiler available in Tools/Oberon - Native Oberon on A2 - is called PACO? I thought that it was OP2, and that it was broken on A2?


Title: Re: Need help with this code
Post by: staubesv on August 06, 2010, 03:38:10 PM
PACO is itself an A2 application but it can also be used to compile "Oberon" programs that later run under "A2 Oberon" (Oberon system running as application on A2).
OP2 is a Oberon application. Originally, it could also compile A2 programs that later run under A2, but some time ago, it was not maintained anymore. Now, Oberon programs compiled with OP2 (under "A2 Oberon") will run neither on A2 nor "A2 Oberon" because the object file generated by OP2 is not compatible to the A2 loader anymore (which also loads object files used by "A2 Oberon").

Native Oberon: The OP2 compiler that comes with Native Oberon is not affected by this issue and works as expected.


Title: Re: Need help with this code
Post by: dukester on August 06, 2010, 03:58:19 PM
Thanks for clearing that up!