Oberon Community Platform Forum
September 25, 2017, 09:10:17 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: FAQ  (Read 2360 times)
rmitin
Moderator
Newbie
*****
Posts: 22


FAQ
« on: June 02, 2009, 08:42:14 AM »

I want to remove Zonnon group on google groups as it attracts too much spam and not really useful. So I'm copypasting here the FAQ. So here are the answers on old questions that were published .

Question:
Is it possible to extend a .Net class in Zonnon? I should like to add
some new methods to System.Xml.XmlDocument, but I didn't found the way
to do it.

Answer:
Please find below an example on inheriting from Windows.Forms.Form.
OnPaint method in this example shows how to use overriding.
module Main;
import  System,
           System.Windows.Forms as Forms,
           System.Drawing as Drawing;

type {public, ref} MainForm = object implements Forms.Form
var {public}
        exitButton : Forms.Button;
        change : integer;

procedure {public} OnPaint(e : Forms.PaintEventArgs) implements
Forms.Form.OnPaint;
var
        g : Drawing.Graphics;
begin
        g := e.Graphics;
        g.DrawRectangle(Drawing.Pens.LimeGreen, 10, 10, 100, 100)
end OnPaint;

procedure {public} onMouseEnter( sender:object; args:
System.EventArgs);
begin
    inc(change);
        case change of
          1:    exitButton.Left := Width - exitButton.Left
        | 2:    exitButton.Text := "exIt";
                        exitButton.Width := exitButton.Width * 2;
                        exitButton.Height := exitButton.Height * 2;
        | 3:    exitButton.Left := Width - exitButton.Left
        | 4:    exitButton.Text := "Exit";
                        exitButton.Width := exitButton.Width div 2;
                        exitButton.Height := exitButton.Height div 2;
        else
          change := 0
        end

end onMouseEnter;

procedure {public} onExit( sender:object; args: System.EventArgs);
begin
        Forms.Application.Exit;
end onExit;

begin
        Text := "My Zonnon Windows Application";
        Width  := 340;
        Height := 280;
        change := 0;
        exitButton := new Forms.Button;
        exitButton.Text := "Exit";
        exitButton.Left := Width div 2 - exitButton.Width div 2;
        exitButton.Top := Height div 2 - exitButton.Height div 2 - 40;
        exitButton.add_MouseEnter(onMouseEnter);
        exitButton.add_MouseLeave(onMouseEnter);
        exitButton.add_Click(onExit);
        Controls.Add(exitButton);
        CenterToScreen;
end MainForm;

var mainForm: MainForm;
begin
        mainForm := new MainForm;
        Forms.Application.Run(mainForm);
end Main.

--------------------------------------------------

Question:
Why my code does not compile anymore? How to use import statement in Zonnon?

Answer:
This message is to clarify the use of import and the change in what
1.0.78 compiler expects.
There are no changes has been made. The fact is that language report
underspecified the use of import statement which could lead to various
interpretations. Before compiler tried to support all of them. The
change is that now it sticks to only one official so some code can
become not compilable. These clarifications will be added to the
language report with its next revision.

Use of import.
Case 1: To allow use one _module_ from another _module_. Nested
objects should not import modules.

module A;
var {public} x: integer;

end A.

module B;
import A; (* it does not exposes, but only allows the use of
declarations qualified by A*)
begin
  A.x := 10; (*The use*)
end B.

Case 2: To allow the use of declarations defined in name spaces of
external libraries

module Main;
import System.Threading.Thread; (* Allows the use*)

begin
   System.Threading.Thread.Sleep( 500 ); ( * The actual use *)
end Main.

Renaming: "as" clause can be used to give another name for the
imported module within the scope of the module. Renaming can be
applied in all cases.

module Main;
import System.Threading.Thread as Thread; (* Allows the use*)

begin
   Thread.Sleep( 500 ); ( * The actual use. Qualified by the new name
given in import*)
end Main.

Case 3: Top level objects. Objects declared outside modules may use
import to gain access to other modules. The fact is that top level
objects are merged with anonymous modules. So the import is applied to
the module

object O;
import M;
end O.

module M;
end M.

The object declaration above actually means
module <no name>;
import M;
type {public} O = object
end O;
end <no name>.

Case 3: objects can import implementations. Default implementations
for definitions that the object implements are imported automatically.
No need to write it explicit. Still there is a possibility to import
other implementations (out of the scope of this message).

If there is a code where nested object imports something this will not
work anymore

module M;
type {ref} O = object
 import System.Double; (* Wrong. It will look for an implementation
System.Double within the scope of M*)
end O;
end M.

Replace it with

module M;
import System.Double; (* Correct. *)
type {ref} O = object
  (* System.Double is visible from here since it has been imported by
the enclosing module*)
end O;
end M.

Question:
I can't compile your example module. I get follow message:

Zonnon Compiler, Version 1.0.0.45
(c) 2003-2005 ETH Zurich
D:\Dev\Zonnon\ZonnonChess\11\XYDrawing.znn
[12,25] [2015] Name 'Size' cannot be used in import declaration or in
REFINES/IMPLEMENTS clause
[13,26] [2015] Name 'Point' cannot be used in import declaration or in
REFINES/IMPLEMENTS clause
[14,30] [2015] Name 'Rectangle' cannot be used in import declaration
or in REFINES/IMPLEMENTS clause
...
[61,2] [2107] Illegal type of the left or right part of the assignment
statement
[74,18] [2030] Entity 'Application' is not declared
[16,17] [2016] Name 'Graphics' does not denote a type as expected
End of messages
The path has been compiled: D:\Dev\Zonnon\ZonnonChess\11\XYDrawing.znn

Answer:
You should link system libraries that contain classes used for user
interface.
You can find them in following folders:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Windows.Forms.dll
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Drawing.dll

--------------------------------------------------

Question:
I would ask about the existence of a primitive operation for returning
a "real time" notion (machine dependent) to a zonnon program. In other
words, I'm wondering about an operation similar to
System.currentTimeMillis() of Java.

Answer:
Since the first compiler for Zonnon is implemented on Microsoft .NET
Framework you can use all FCL classes. I think nearest to Java's
System.currentTimeMillis() on .NET will be System.DateTime.Now.Ticks.
See Zonnon example below:

module run;
import System;

var
  dt: System.DateTime;
begin
  dt := System.DateTime.Now;
  writeln(dt.Ticks);
end run.

--------------------------------------------------

Question:
What is the behavior of these functions if the preconditions are not
met. Will they raise an exception or is the behavior implementation
dependent (undefined)?
Answer:
Generally missing the preconditions means an exception. Thus succ,
pred and cup will raise an exception if the preconditions are not met.

--------------------------------------------------

Question:
Am I right when I assume that I can't write a scanner using 'read(ch)'
because spaces and line feeds get silently ignored just as with 'cin

>> ch' in C++?

Answer:
Read - is just a shortcut (e.g. for educational purpose) for
corresponding .NET functions. To get the most of input features (real
programming) you have to use .NET functions. For a scanner you will
probably need not only console, but input form a file.

Example on using .NET FCL from Zonnon for output to a file:
module Example102;
import System, System.IO;
type
  SW = System.IO.StreamWriter;
var
  sw : SW;
  fn : System.String;
begin
  fn := "myfile.txt";
  sw := new System.IO.StreamWriter(fn, false);
  sw.Write("Text to be written to file");
  sw.Close();
end Example102.

--------------------------------------------------

Question:
I could not find any notice why you call the language Zonnon. What
does zonnon mean?

Answer:
The name has the only meaning - it is the name of this language. If
you try to find "Zonnon" with e.g. Google you'll find nothing except
links to this project. The name sounds close to "Oberon" since this
language continuous its line. The first letter ('Z' - the last letter
of the English alphabet) may mean that it is the final language among
this line.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!