Contents
-
DEFINE (S, D, U)
-
DO (S, D, U)
-
EACH (S, D, U)
-
EXIT (S, D, U)
-
FIND (S, D, U)
-
FROM (S, D, U)
-
IF (S, D, U)
-
PRINT (S, D, U)
-
SWITCH (S, D, U)
-
TO (S, D, U)
-
TYPEOF (S, D, U)
-
WHILE (S, D, U)
DEFINE
Identifier
LABEL
StringContant
EXTENDS
Identifier
,
Identifier
[
eol
Attribute Definitions
Element Definitions
Method Definitions
]
eol
|
Attribute Definitions |
STATIC
@
Ident
!?
=
Expression
TYPEOF
Identifier
LABEL
StringConstant
eol
|
Element Definitions |
-
First Form
-
STATIC
Ident
*
!?
=
Expression
TYPEOF
Identifier
LABEL
StringConstant
eol
-
Second Form
-
STATIC
Ident
*
!?
LABEL
StringConstant
[
eol
Attribute Definitions
Element Definitions
]
eol
|
Method Definitions |
STATIC
:
Identifier
(
Ident
Typeof
Indetifier
,
Ident
Typeof
Indetifier
)
[
eol
StatmentBlock
]
TYPEOF
Identifier
eol
|
|
Concept declarations define new concept types and describe how
they are implemented.
The body of the concept declares members (elements, attributes
and methods), constructors, operators. The members of a concept
include both declared and inherited members. Newly declared
elements, attributes can hide fields declared in an superconcept.
Newly declared members can hide, implement or override
methods declared in superconcepts.
Method declarations describe code that may be invoked by method
invocation expressions.
The optional EXTENDS clause in a concept declaration specifies
the direct superconcepts of the current concept. One concept can
extend zero or more concepts. If there are elements, attributes,
methods which conflicts in the superclasses (have the
same signature), the element, attribute, method of the
leftmost concept will be inherited, the other being disregarded.
If an element or attribute of the concept is declared STATIC,
there exists exactly one incarnation of the element or attribute, no
matter how many instances of the concept may be created.
If a method of the concept is declared STATIC, it is invoked
without the reference to a particular concept instances. Methods
that are not defined STATIC are always invoked with respect to an
concept instance.
Every concept, attribute or element can have an assigned label.
This assigned label will be used (if defined) for the automatic
rendering of the concept. Otherways the concept, element or
attribute name will be used.
In case the TYPEOF optional clause is used on a attribute,
element, parameter, or return type, the type of the respective items
will be enforced to the declared type of concept. Other-way the
items are considered free type and any concept can be assigned to
them.
We name the signature of an method or concept the ensemble formed
by the name, number of parameters, the type of parameters and the
return type of the method or concept.
Constructors always have the create
name. More
constructors are allowed if the signature of the constructors are
different.
Methods always begin with the :
character. More methods
are allowed with the same name if the signature of the methods are
different.
Every concept is derived from the Concept concept automaticaly
therefore explicitly specifying this inheritance is not recommended.
|
define PersonDefineExample label "person" [
@firstName typeof String label "FirstName"
@lastName typeof String label "LastName"
email
location* [
address typeof PersonDefineExample:Address label "Address"
]
static : main ( $args typeof Series ) [
$me typeof PersonDefineExample
$me@firstName = "Remus"
$me@lastName = "Pereni"
$me/email = "remus@nolimits.ro"
$me/location.createNewEntry
$me/location.lastEntry/address@type = "HOME"
$me/location.lastEntry/address/str = "Bld. Octavian Goga 4/7"
$me/location.lastEntry/address/city = "Satu Mare"
$me/location.lastEntry/address/zipCode = PersonDefineExample:Address.getZipCode("Satu Mare")
$me/location.createNewEntry
$me/location.lastEntry/address@type = "WORK"
$me/location.lastEntry/address/city = "Satu Mare"
$me/location.lastEntry/address/zipCode = PersonDefineExample:Address.getZipCode("Satu Mare")
print $me.toXML
print "And now some text"
print $me
]
: toTXT [
$result = @firstName + " " + @lastName + " (" + /email/ + ")" + Character.getEOLChar
each $loc in /location/ do [
$result += $loc/address.toTXT
]
return $result
] typeof String
]
define PersonDefineExample:Address extends PersonDefineExample:SomeAddress [
@type typeof String label "addressType"
zipCode typeof Element
static : getZipCode( $city typeof String ) [
if $city == "Satu Mare" then [
return "3900"
] else [
return "unknown"
]
] typeof String
: toTXT [
$result = ""
$result += "\t" + @type + " address" + Character.getEOLChar
$result += "\t\t" + /str/ + Character.getEOLChar
$result += "\t\t" + /zipCode/ + ", " + /city/ + Character.getEOLChar
$result += "\t\t" + /country/ + Character.getEOLChar
return $result
] typeof String
]
define PersonDefineExample:SomeAddress [
str typeof Element
city
country = "Romania" typeof Element
]
------ The result is ------
<person LastName="Pereni" FirstName="Remus">
<email>remus@nolimits.ro</email>
<location>
<Address addressType="HOME">
<str>Bld. Octavian Goga 4/7</str>
<city>Satu Mare</city>
<country>Romania</country>
<zipCode>3900</zipCode>
</Address>
</location>
<location>
<Address addressType="WORK">
<str></str>
<city>Satu Mare</city>
<country>Romania</country>
<zipCode>3900</zipCode>
</Address>
</location>
</person>
And now some text
Remus Pereni (remus@nolimits.ro)
HOME address
Bld. Octavian Goga 4/7
3900, Satu Mare
Romania
WORK address
3900, Satu Mare
Romania
|
|
DO [
eol
StatementBlock
] WHILE
LogicalExpression
eol
|
|
The do-while statement specify the
repeated execution of an block until the logical expression (it's
guard) yields true. The guard is checked after every execution of
the statement block (that means the statement block is always
executed at least once).
|
$i = 0
do [
++$i
print "$i is: ", $i
] while $i < 10
------ The result is -----
$i is: 1
$i is: 2
$i is: 3
$i is: 4
$i is: 5
$i is: 6
$i is: 7
$i is: 8
$i is: 9
$i is: 10
Another example, in which we use a series is:
$s typeof Series
$s.add("White")
$s.add("Black")
$s.add("Blue")
$s.add("Red")
$s@index = $s@length
do [
print $s.previous
] while $s@hasPrevious
------ The result is -----
Blue
Black
White
|
|
First Form |
EACH
Ident
IN
SeriesExpression
WHERE
LogicalExpression
BREAK
BY
Ident
DO [
eol
StatementBlock
]
eol
|
Second Form |
EACH
Ident
FROM
StringExpression
OPTIONS
StringExpression
=
Expression
,
StringExpression
=
Expression
WHERE
LogicalExpression
BREAK
BY
Ident
DO [
eol
StatementBlock
]
eol
|
|
The EACH statement enumerates and filters, elements from a Series
concept. The Series concept can be explicitly used in case of use of
the IN keyword or automaticaly produced by the FROM statement.
The EACH statement is composed from:
- a data source represented by the IN $series keyword or the FROM statement.
- a filtering block represented by the WHERE block
- a ordering and signalizing block represented by the BY and BREAK clause.
Every concept from the data source is considered valid if the
clauses in the WHERE block evaluates to TRUE. There is no limitation
in what clauses can be included in the WHERE block.
The order in which the concepts from the Series are returned can
be influenced through the use of the BY keyword.
Signaling is possible through the BREAK keyword which should
proceed the BY. Two functions will be valid inside a EACH statement:
|
An example of the first form in which all the composing elements of the each
keyword are used can be seen bellow.
$dataString = "
<people>
<person name='Remus Pereni'>
<address>
<city>Satu Mare</city>
<country>Romania</country>
</address>
<age>27</age>
</person>
<person name='Sorin Iluti'>
<address>
<city>Satu Mare</city>
<country>Romania</country>
</address>
<age>28</age>
</person>
<person name='Daniel Taut'>
<address>
<city>Tilburg</city>
<country>Netherland</country>
</address>
<age>26</age>
</person>
</people>"
$people = Concept.fromXML($dataString)
each $person in $people/person/ where Integer.create($person/age/) > 20 \
break by $person/address/country/ descending \
by $person/address/city/ \
by $person@name ascending do [
if first $person/address/country/ then [
print "===== ", $person/address/country/, " ====="
]
if first $person/address/city/ then [
print "In: ", $person/address/city/
]
print $person@name, " Age:", $person/age/
]
------ The result is -----
===== Romania =====
In: Satu Mare
Remus Pereni Age:27
Sorin Iluti Age:28
===== Netherland =====
In: Tilburg
Daniel Taut Age:26
An example of the second form in which all the composing elements of the each
keyword are used can be seen bellow.
# we filter the files from the e:\tmp\mref directory as follows
# - only the files at most two directories deep but not exceeding 100 files
# - all the files who's content type is different than octet-stream
# - the files should have the size bigger than 1000 bytes
# - the files url should not contain concept
each $file from "e:\\tmp\\mref\\" \
options "depth"=2, "requests"=100 \
where $file@contentType != "application/octet-stream" \
and $file@length > 1000 \
and $file@url.indexOf("concepts") == -1 \
break by $file@contentType \
by $file@length do [
if first($file@contentType) then [
print "----- ", $file@contentType, " files -----"
]
print $file@url, " (Length: " , $file@length, " bytes)"
]
------ The result is -----
----- application/zip files -----
file:/e:/tmp/mref/ref.zip (Length: 10157 bytes)
----- text/css files -----
file:/e:/tmp/mref/res/mref.css (Length: 1153 bytes)
----- text/html files -----
file:/e:/tmp/mref/categories/testing_mn8unit.html (Length: 1276 bytes)
file:/e:/tmp/mref/categories/system_advanced.html (Length: 1570 bytes)
file:/e:/tmp/mref/reference/index.html (Length: 2693 bytes)
file:/e:/tmp/mref/categories/system_base_mn8unit.html (Length: 3310 bytes)
file:/e:/tmp/mref/reference/langref.html (Length: 5898 bytes)
file:/e:/tmp/mref/categories/index.html (Length: 7485 bytes)
file:/e:/tmp/mref/categories/system_base.html (Length: 19271 bytes)
file:/e:/tmp/mref/reference/keyref.html (Length: 42663 bytes)
file:/e:/tmp/mref/index_all.html (Length: 113519 bytes)
----- text/xml files -----
file:/e:/tmp/mref/reference/langref.html.xml (Length: 1529 bytes)
file:/e:/tmp/mref/reference/keyref.html.xml (Length: 23922 bytes)
|
|
exit
( IntegerExpression
)
|
|
Terminates the execution of the current script.
The optional argument which must evaluate to an integer is giving the exit
status (defaulting to zero).
If it is an integer, zero is considered ``successful termination'' and
any nonzero value is considered ``abnormal termination'' by shells and
the like. Most systems require it to be in the range 0-127, and produce
undefined results otherwise. Some systems have a convention for
assigning specific meanings to specific exit codes, but these are
generally underdeveloped; Unix programs generally use 2 for command line
syntax errors and 1 for all other kind of errors.
|
|
First Form |
FIND
FIRSTLAST
Ident
IN
SeriesExpression
WHERE
LogicalExpression
BREAK
BY
Ident
eol
|
Second Form |
FIND
FIRSTLAST
Ident
FROM
StringExpression
OPTIONS
StringExpression
=
Expression
,
StringExpression
=
Expression
WHERE
LogicalExpression
BREAK
BY
Ident
eol
|
|
The FIND statement allows the selection of a first or last concept
from an external data source (FROM) or from a Series, source which mach the
restrictions imposed by the WHERE clause.
|
An example of the first form in which all the composing elements of the find
keyword are used can be seen bellow.
$dataString = "
<people>
<person name='Remus Pereni'>
<address>
<city>Satu Mare</city>
<country>Romania</country>
</address>
<age>27</age>
</person>
<person name='Sorin Iluti'>
<address>
<city>Satu Mare</city>
<country>Romania</country>
</address>
<age>28</age>
</person>
<person name='Daniel Taut'>
<address>
<city>Tilburg</city>
<country>Netherland</country>
</address>
<age>26</age>
</person>
</people>"
$people = Concept.fromXML($dataString)
find first $person in $people/person/ where Integer.create($person/age/) > 20 \
break by $person/address/country/ descending \
by $person/address/city/ \
by $person@name ascending
print "The first person is: ", $person@name, " Age:", $person/age/
find last $person in $people/person/ where Integer.create($person/age/) > 20 \
break by $person/address/country/ descending \
by $person/address/city/ \
by $person@name ascending
print "The last person is: ", $person@name, " Age:", $person/age/
------ The result is ------
The first person is: Remus Pereni Age:27
The last person is: Daniel Taut Age:26
An example of the second form in which all the composing elements of the find
keyword are used can be seen bellow.
find first $file from "e:\\tmp\\mref\\" \
options "depth"=2, "requests"=100 \
where $file@contentType != "application/octet-stream" \
and $file@length > 1000 \
and $file@url.indexOf("concepts") == -1 \
break by $file@contentType \
by $file@length
print "The first file of the type: ", $file@contentType, " is"
print $file@url, " (Length: " , $file@length, " bytes)"
find last $file from "e:\\tmp\\mref\\" \
options "depth"=2, "requests"=100 \
where $file@contentType != "application/octet-stream" \
and $file@length > 1000 \
and $file@url.indexOf("concepts") == -1 \
break by $file@contentType \
by $file@length
print "The last file of the type: ", $file@contentType, " is"
print $file@url, " (Length: " , $file@length, " bytes)"
------ The result is -----
The first file of the type: text/css is
file:/e:/tmp/mref/res/mref.css (Length: 1153 bytes)
The last file of the type: text/xml is
file:/e:/tmp/mref/reference/keyref.html.xml (Length: 28469 bytes)
|
|
Ident
FROM
StringExpression
OPTIONS
StringExpression
=
Expression
,
StringExpression
=
Expression
eol
|
|
The FROM statement allows retrieval and navigation
operations over a wide variety of mediums. Because there is rarely a
uniformity in operating in this mediums the OPTION keyword allows
the specification of medium specific parameters.
The medium coverage will is realized through a API so new
protocol handler modules can be added in time.
|
$page from "http://www.zeldman.com"
$expr = Regexp.create("(?mi)^<dd><a href=\"(.*?)\".*title=\"(.*?)\".*?>(.*?)</a></dd>$")
$sel1 = $page/content.select($expr)
each $itm in $sel1 do [
print $itm/3/
print "\t", $itm/1/
print "\t", Tag.getStrippedText($itm/2/, false)
]
------ The result is ------
Digital Web
http://www.digital-web.com/
The web designers online magazine of choice.
iStockphoto
http://www.istockphoto.com/
Free photography for your design projects.
K10k
http://www.k10k.net/
Design content and news.
New Riders
http://www.newriders.com/
Publishing voices that matter.
Pixelsurgeon
http://www.pixelsurgeon.com/
Design content and news.
Another example:
$list from "env:/system/properties" options "DEPTH"= "4",\
"FILTER"= Simplex.create("*user*")
each $name in $list do [
$val from $name
print $name, "=", $val
]
------ The result is ------
env:/system/properties/user.name=Remus Pereni
env:/system/properties/user.language=ro
env:/system/properties/user.timezone=
env:/system/properties/user.country=RO
env:/system/properties/user.variant=
env:/system/properties/user.home=C:\Documents and Settings\Remus Pereni
env:/system/properties/user.dir=E:\devel\SPACEM~1\mn8\examples\STATEM~1
|
|
IF
LogicalExpression
THEN [
eol
StatementBlock
]
ELIF
LogicalExpression
THEN [
eol
StatementBlock
]
ELSE [
eol
StatementBlock
]
eol
|
|
It selects exactly one of the blocks by
evaluating the expressions one by one until one is found to be true
then that block is executed (and no other part of the if statement
is executed or evaluated). If all expressions are false, the block
of the else clause, if present, is executed.
|
Simple if example.
if 100 > 10 then [
print "Sure 100 is greater than 10 :)"
]
------ The result is ------
Sure 100 is greater than 10 :)
Another example.
$series typeof Series
$series.add("It's a String") # String
$series.add(1) # Integer
$series.add(2.3) # Real
$series.add(false) # Logical
$series.add('\t') # Character
each $item in $series do [
if $item.getConceptType == String.getConceptType then [
print "it is an string"
] elif $item.getConceptType == Integer.getConceptType then [
print "it is an integer"
] elif $item.getConceptType == Real.getConceptType then [
print "it is an real"
] elif $item.getConceptType == "Logical" then [
print "it is an logical"
] else [
print "it is an character"
]
]
------ The result is ------
it is an string
it is an integer
it is an real
it is an logical
it is an character
|
|
SWITCH
Expression
[
eol
CASE
Expression
[
StatementBlock
]
ELSE [
eol
StatementBlock
]
eol
|
|
The switch statement transfers control to one of several statements
blocks depending on the value of an expression.
If the _EXPRESSION_ matches any _CONSTANT_EXPRESSION_, the code
block related to the constant expression is executed. If none of the
constant expression are matched and the ELSE statement block is
present then the ELSE related code block is executed.
|
$s typeof Series
$s.add("White")
$s.add("Black")
$s.add("Blue")
$s.add("Red")
each $color in $s do [
switch $color [
case "White" [
print "The current color is white"
]
case "Black" [
print "The current color is black"
]
else [
print "Is other than white or black"
]
]
]
------ The result is -----
The current color is white
The current color is black
Is other than white or black
Is other than white or black
Another example.
$series typeof Series
$series.add("It's a String") # String
$series.add(1) # Integer
$series.add(2.3) # Real
$series.add(false) # Logical
$series.add('\t') # Character
each $item in $series do [
switch $item.getConceptType [
case String.getConceptType [
print "it is an string"
]
case Integer.getConceptType [
print "it is an integer"
]
case Real.getConceptType [
print "it is an real"
]
case Logical.getConceptType [
print "it is an logical"
]
case "Character" [
print "it is an character"
]
]
]
------ The result is -----
it is an string
it is an integer
it is an real
it is an logical
it is an character
|
|
Expression
TO
StringExpression
OPTIONS
StringExpression
=
Expression
,
StringExpression
=
Expression
eol
|
|
The TO statement allows store operations over a wide variety of
mediums. Because there is rarely a uniformity in operating in this
mediums the OPTION keyword allows the specification of medium
specific parameters.
The medium coverage will is realized through a API so new
protocol handler modules can be added in time.
|
$rssPage from "http://radio.weblogs.com/0100887/rss.xml"
$myDir from "env:/system/properties/user.home"
$rssPage/content/ to $myDir + File.getSeparator + "JonUdell_" + Date.getToday.getDate("yyyyMMMd") + "_RSS.xml"
Another example:
$message = "From: someoane@somenet.net\n"
$message += "To: you@email.address\n"
$message += "Subject: Hello it's a test :)\n"
$message += "This is the actual message!\n"
$myDir to "smtp://your_smtp_server"
Another example:
$rssPage from "http://radio.weblogs.com/0100887/rss.xml"
$rssPage/content/ to "ftp://your.ftp.server/home/user/rss.xml" options "user"="userName", "pwd"="yourPassword"
|
|
First Form |
Ident
TYPEOF
StringExpression
eof
|
Second Form |
Ident
TYPEOF
Identifier
eof
|
|
MN8 is dynamically typed, that means that the interpreter will
try to figure by himself what kind of type a variable is and can be.
However because of the nature of concepts (inheritance,
initialization, constructors) sometimes we need a finer graining
system for enforcing a particular concept type to a variable.
The TYPEOF keyword enforce a particular concept type specified by
the Concept option to an indentifier or the result of an expression
which evaluates to a string.
A variables type can be unlocked by assigning a TYPEOF Nil. In
this way the variable becomes free to have any kind of type again.
|
An example of the first form:
$s typeof Series
$s.add("Element")
$element typeof $s/1/
$element.setLabel("MyElement")
$element.addAttribute(Attribute.create("attribute", "attrValue"))
$element.setValue("The Element Value")
print $element.toXML
------ The result is -----
<MyElement attribute="attrValue">The Element Value</MyElement>
An example of the second form:
$element typeof Element
$element.setLabel("MyElement")
$element.addAttribute(Attribute.create("attribute", "attrValue"))
$element.setValue("The Element Value")
print $element.toXML
------ The result is -----
<MyElement attribute="attrValue">The Element Value</MyElement>
|
|
WHILE
LogicalExpression
DO [
eol
StatementBlock
]
eol
|
|
The while statement is used for repeated execution as long as an
expression is true.
|
$i = 1
while $i < 10 do [
print "$i is:", $i , " and is less than 10"
++$i
]
------ The result is -----
$i is:1 and is less than 10
$i is:2 and is less than 10
$i is:3 and is less than 10
$i is:4 and is less than 10
$i is:5 and is less than 10
$i is:6 and is less than 10
$i is:7 and is less than 10
$i is:8 and is less than 10
$i is:9 and is less than 10
Another example, in which we use a series is:
$s typeof Series
$s.add("White")
$s.add("Black")
$s.add("Blue")
$s.add("Red")
while $s@hasNext do [
print $s.next
]
------ The result is -----
White
Black
Blue
Red
|
|
|