Code examples
Contens
Hello world!
back to top
app PeaceKeeper
{
on Enter =>
{
"Begin" >> @>log;
"End" >> @>log;
}
}
Enter life cycle trigger is executed. Strings are wrritten into log channel.
Comments
back to top
Single line comment
back to top
Read more about Single line comment here.
app PeaceKeeper
{
on Enter =>
{
"Begin" >> @>log;
@bx >> @>log;
"End" >> @>log;
}
}
Multi line comment
back to top
Read more about Multi line comment here.
app PeaceKeeper
{
on Enter =>
{
"Begin" >> @>log;
"End" >> @>log;
}
}
NULL
Read more about NULL here.
app Example
{
on Enter =>
{
'Begin' >> @>log;
@x = NULL;
@x >> @>log;
'End' >> @>log;
}
}
Variables
back to top
Read more about Variables here.
Example 1
back to top
Here 1 is alternately assigned to variables @r and @b.
So the variable @b will contain 1.
app PeaceKeeper
{
on Enter =>
{
"Begin" >> @>log;
@r = @b = 1;
@b >> @>log;
"End" >> @>log;
}
}
Example 2
back to top
A variable @bx has never been being assigned. So It contains default value NULL.
app PeaceKeeper
{
on Enter =>
{
"Begin" >> @>log;
@r = @b = 1;
@bx >> @>log;
"End" >> @>log;
}
}
Example 3
app PeaceKeeper
{
on Enter =>
{
'Begin' >> @>log;
var @a: number = 2;
@a >> @>log;
var @b: number;
@b >> @>log;
var @c;
@c >> @>log;
'End' >> @>log;
}
}
Object literal
back to top
Read more about Object literal here.
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
var @a = {
@b = 1;
};
@a.@b >> @>log;
'End' >> @>log;
}
}
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
var @a = {
@b = 1;
};
@a.@b = 2;
@a.@b >> @>log;
'End' >> @>log;
}
}
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
var @c = SomeFun();
@c.@b >> @>log;
'End' >> @>log;
}
fun SomeFun()
{
var @a = {
@b = 1;
};
return @a;
}
}
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
SomeFun().@b >> @>log;
'End' >> @>log;
}
fun SomeFun()
{
var @a = {
@b = 1;
};
return @a;
}
}
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
OtherFun({
@b = 1;
});
'End' >> @>log;
}
fun OtherFun(@param)
{
@param.@b >> @>log;
}
Linguistic variable
back to top
Read more about Linguistic variable here.
Full declaration
back to top
linvar age for range (0, 150]
{
constraints:
for inheritance;
for relation age;
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
linvar logic for range [0, 1]
{
constraints:
for inheritance;
terms:
minimal = L(0, 0.1);
low = Trapezoid(0, 0.05, 0.3, 0.45);
middle = Trapezoid(0.3, 0.4, 0.6, 0.7);
high = Trapezoid(0.55, 0.7, 0.95, 1);
maximal = S(0.9, 1);
}
Minimal declaration
back to top
linvar age
{
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
linvar age
{
`teenager` = Trapezoid(10, 12, 17, 20);
}
With ranges
back to top
linvar age for range (-∞, +∞)
{
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
This range is also from negative infinity to positive infinity:
linvar age for range (*, *)
{
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
This range is open.
linvar age for range (0, 150)
{
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
This range is closed.
linvar age for range [0, 150]
{
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
This range is left-open and right-closed.
linvar age for range (0, 150]
{
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
This range is left-closed and right-open.
linvar age for range [0, 150)
{
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
With constraints
back to top
linvar age
{
constraints:
for inheritance;
for relation age;
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
linvar age
{
constraints:
for inh;
for rel age;
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
linvar age for range (0, 150]
{
constraints:
for relation age;
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
linvar age for range (0, 150]
{
constraints:
for rel age;
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
linvar age for range (0, 150]
{
constraints:
for inheritance;
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
linvar age for range (0, 150]
{
constraints:
for inh;
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
Predefined membership functions
back to top
L Function
back to top
linvar age for range (0, 150]
{
`teenager` = L(5, 10);
}
Trapezoid Function
back to top
linvar age for range (0, 150]
{
`teenager` = Trapezoid(10, 12, 17, 20);
}
S Function
back to top
linvar age for range (0, 150]
{
`teenager` = S(12, 17, 22);
}
linvar age for range (0, 150]
{
`teenager` = S(12, 22);
}
Synonym
back to top
Read more here about synonyms in SymOntoClay DSL.
synonym b for a;
app PeaceKeeper
{
fun a() =>
{
'`a` has been called!' >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
b();
'End' >> @>log;
}
}
Begin
`a` has been called!
End
synonym param_1 for param_2;
app PeaceKeeper
{
fun a(@param_1)
{
'`a` has been called!' >> @>log;
@param_1 >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
a(param_2: 1);
'End' >> @>log;
}
}
Begin
`a` has been called!
1
End
synonym procreator for parent;
app PeaceKeeper
{
{: male(#Tom) :}
{: procreator(#Piter, #Tom) :}
{: {son($x, $y)} -> { male($x) & parent($y, $x)} :}
on Enter => {
select {: son($x, $y) :} >> @>log;
}
}
<yes>
$y = #piter; $x = #tom
synonym procreator for parent;
synonym #Tom for #Person123;
app PeaceKeeper
{
{: male(#Tom) :}
{: procreator(#Piter, #Person123) :}
{: {son($x, $y)} -> { male($x) & parent($y, $x)} :}
on Enter => {
select {: son($x, $y) :} >> @>log;
}
}
<yes>
$y = #piter; $x = #tom
synonym go for walk;
app PeaceKeeper
{
on Enter =>
{
'Begin' >> @>log;
walk();
'End' >> @>log;
}
}
action Go
{
on Enter =>
{
'Enter Go' >> @>log;
}
op () =>
{
'Begin Go' >> @>log;
'End Go' >> @>log;
}
}
Begin
Enter Go
Begin Go
End Go
End
synonym Chilling for Idling;
app PeaceKeeper
{
set Chilling as default state;
on Enter =>
{
'Begin' >> @>log;
'End' >> @>log;
}
}
state Idling
{
on Enter
{
'Begin Enter' >> @>log;
'End Enter' >> @>log;
}
}
Begin
Begin Enter
End
End Enter
Inheritance
back to top
Here It is example of changing relationship run time using operator "is" and statement "set is".
Read more here about inheritance in SymOntoClay DSL.
app PeaceKeeper is [0.5] exampleClass
{
on Enter =>
{
"Begin" >> @>log;
exampleClass is human >> @>log;
exampleClass is not human >> @>log;
set exampleClass is [0.5] human;
exampleClass is human >> @>log;
exampleClass is not human >> @>log;
set exampleClass is not human;
exampleClass is human >> @>log;
exampleClass is not human >> @>log;
set @@self is linux;
@@self is linux >> @>log;
"End" >> @>log;
}
}
Using non-numeric fuzzy value:
linvar logic for range [0, 1]
{
constraints:
for inheritance;
terms:
minimal = L(0, 0.1);
low = Trapezoid(0, 0.05, 0.3, 0.45);
middle = Trapezoid(0.3, 0.4, 0.6, 0.7);
high = Trapezoid(0.55, 0.7, 0.95, 1);
maximal = S(0.9, 1);
}
app PeaceKeeper is [middle] exampleClass
{
on Enter =>
{
'Begin' >> @>log;
exampleClass is human >> @>log;
exampleClass is not human >> @>log;
set exampleClass is [middle] human;
exampleClass is human >> @>log;
exampleClass is not human >> @>log;
set exampleClass is not human;
exampleClass is human >> @>log;
exampleClass is not human >> @>log;
set @@self is linux;
@@self is linux >> @>log;
'End' >> @>log;
}
}
linvar logic for range [0, 1]
{
constraints:
for inheritance;
terms:
minimal = L(0, 0.1);
low = Trapezoid(0, 0.05, 0.3, 0.45);
middle = Trapezoid(0.3, 0.4, 0.6, 0.7);
high = Trapezoid(0.55, 0.7, 0.95, 1);
maximal = S(0.9, 1);
}
app PeaceKeeper is [very middle] exampleClass
{
on Enter =>
{
'Begin' >> @>log;
exampleClass is human >> @>log;
exampleClass is not human >> @>log;
set exampleClass is [very middle] human;
exampleClass is human >> @>log;
exampleClass is not human >> @>log;
set exampleClass is not human;
exampleClass is human >> @>log;
exampleClass is not human >> @>log;
set @@self is linux;
@@self is linux >> @>log;
'End' >> @>log;
}
}
Additional settings
back to top
Read more about Additional settings here.
Priority
back to top
Read more about Priority here.
app PeaceKeeper
{
fun a() with priority = 1 =>
{
'`a` has been called!' >> @>log;
@a = 10;
while (@a > 0)
{
@a >> @>log;
@a = @a - 1;
}
'End `a`' >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
@a = a~~();
wait @a;
'End' >> @>log;
}
}
app PeaceKeeper
{
on {: see(I, #a) :} with priority 1 =>
{
'D' >> @>log;
}
}
app PeaceKeeper
{
on {: see(I, #a) :} as `trigger 1` alias `Alarm trigger`, trigger_5 with priority 1 =>
{
'D' >> @>log;
}
}
app PeaceKeeper
{
on {: see(I, #a) :} as `trigger 1` with priority 1 =>
{
'D' >> @>log;
}
}
app PeaceKeeper
{
on {: see(I, $x) :}($x >> @x) with priority 1 =>
{
'on Fired $x in App' >> @>log;
@x >> @>log;
}
}
Member access modifiers
back to top
Read more about Member access modifiers here.
class Cls1
{
protected:
fun a() =>
{
'`a` has been called!' >> @>log;
}
}
app PeaceKeeper is Cls1
{
private:
on Enter =>
{
'Begin' >> @>log;
a();
'End' >> @>log;
}
}
Begin
`a` has been called!
End
class Cls1
{
private:
{: male(#Tom) :}
{: parent(#Piter, #Tom) :}
{: {son($x, $y)} -> { male($x) & parent($y, $x)} :}
}
app PeaceKeeper is Cls1
{
private:
on Enter =>
{
'Begin' >> @>log;
select {: son($x, $y) :} >> @>log;
'End' >> @>log;
}
}
class Cls1
{
protected:
{: male(#Tom) :}
{: parent(#Piter, #Tom) :}
{: {son($x, $y)} -> { male($x) & parent($y, $x)} :}
}
app PeaceKeeper is Cls1
{
private:
on Enter =>
{
'Begin' >> @>log;
select {: son($x, $y) :} >> @>log;
'End' >> @>log;
}
}
Begin
<yes>
$y = #piter; $x = #tom
End
Field
back to top
Read more about Field here.
app PeaceKeeper
{
@b;
on Enter =>
{
'Begin' >> @>log;
@b >> @>log;
'End' >> @>log;
}
}
app PeaceKeeper
{
var @b: number = 2;
on Enter =>
{
'Begin' >> @>log;
@b >> @>log;
'End' >> @>log;
}
}
Constructor
back to top
Read more about Constructor here.
class cls0
{
ctor(@param: string)
{
'Begin ctor 1 of cls0' >> @>log;
@param >> @>log;
@b >> @>log;
'End ctor 1 of cls0' >> @>log;
}
ctor(@param: number)
{
'Begin ctor 2 of cls0' >> @>log;
@param >> @>log;
@b >> @>log;
'End ctor 2 of cls0' >> @>log;
}
private:
@b = 0;
}
class cls1 is cls0
{
ctor(@param: string)
: cls0('Cool!')
{
'Begin ctor of cls1' >> @>log;
@param >> @>log;
@b >> @>log;
'End ctor of cls1' >> @>log;
}
private:
@b = 1;
}
class cls2 is cls0
{
ctor(@param: number)
: cls0(16)
{
'Begin ctor of cls2' >> @>log;
@param >> @>log;
@b >> @>log;
'End ctor of cls2' >> @>log;
}
private:
@b = 2;
}
app PeaceKeeper is cls1, cls2
{
ctor()
: ('Hi')
{
'Begin ctor 1 of PeaceKeeper' >> @>log;
@b >> @>log;
'End ctor 1 of PeaceKeeper' >> @>log;
}
ctor(@param: string)
: cls1('The Beatles!'),
cls2(12)
{
'Begin ctor 2 of PeaceKeeper' >> @>log;
@param >> @>log;
@b >> @>log;
'End ctor 2 of PeaceKeeper' >> @>log;
}
private:
@b = 3;
}
Begin ctor 1 of cls0
Cool!
0
End ctor 1 of cls0
Begin ctor of cls1
The Beatles!
1
End ctor of cls1
Begin ctor 2 of cls0
16
0
End ctor 2 of cls0
Begin ctor of cls2
12
2
End ctor of cls2
Begin ctor 2 of PeaceKeeper
Hi
3
End ctor 2 of PeaceKeeper
Begin ctor 1 of PeaceKeeper
3
End ctor 1 of PeaceKeeper
Function and Method
back to top
Read more about Function here.
Read more about Method here.
app PeaceKeeper
{
fun a() =>
{
'`a` has been called!' >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
a();
'End' >> @>log;
}
}
Begin
`a` has been called!
End
app PeaceKeeper
{
fun a()
{
'`a` has been called!' >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
a();
'End' >> @>log;
}
}
Begin
`a` has been called!
End
app PeaceKeeper
{
fun a(@param_1)
{
'`a` has been called!' >> @>log;
@param_1 >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
a(1);
'End' >> @>log;
}
}
Begin
`a` has been called!
1
End
fun a(@param_1)
{
'`a` (any) has been called!' >> @>log;
@param_1 >> @>log;
}
app PeaceKeeper
{
on Enter =>
{
'Begin' >> @>log;
a(param_1: 1);
'End' >> @>log;
}
}
Begin
`a` (any) has been called!
1
End
app PeaceKeeper
{
fun a(@param_1)
{
'`a` has been called!' >> @>log;
@param_1 >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
a(@param_1: 1);
'End' >> @>log;
}
}
Begin
`a` has been called!
1
End
app PeaceKeeper
{
fun a(@param_1)
{
'`a` has been called!' >> @>log;
@param_1 >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
a(param_1: 1);
'End' >> @>log;
}
}
Begin
`a` has been called!
1
End
app PeaceKeeper
{
fun a(@param_1)
{
'`a` has been called!' >> @>log;
@param_1 >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
@param_1 = 12;
a(@param_1);
'End' >> @>log;
}
}
Begin
`a` has been called!
12
End
app PeaceKeeper
{
fun a(@param_1)
{
'`a` (1) has been called!' >> @>log;
@param_1 >> @>log;
}
fun a(@param_1, @param_2)
{
'`a` (2) has been called!' >> @>log;
@param_1 >> @>log;
@param_2 >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
@param_1 = 12;
a(@param_1);
'End' >> @>log;
}
}
Begin
`a` (1) has been called!
12
End
app PeaceKeeper
{
fun a(@param_1)
{
'`a` (1) has been called!' >> @>log;
@param_1 >> @>log;
}
fun a(@param_1, @param_2)
{
'`a` (2) has been called!' >> @>log;
@param_1 >> @>log;
@param_2 >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
@param_1 = 12;
a(@param_1);
a(3, 'Hi');
'End' >> @>log;
}
}
Begin
`a` (1) has been called!
12
`a` (2) has been called!
3
Hi
End
app PeaceKeeper
{
fun a(@param_1, @param_2 = 15)
{
'`a` (2) has been called!' >> @>log;
@param_1 >> @>log;
@param_2 >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
@param_1 = 12;
a(@param_1);
'End' >> @>log;
}
}
Begin
`a` (2) has been called!
12
15
End
app PeaceKeeper
{
fun a(@param_1)
{
'`a` (any) has been called!' >> @>log;
}
fun a(@param_1: string)
{
'`a` (string) has been called!' >> @>log;
}
fun a(@param_1: number)
{
'`a` has been called!' >> @>log;
@param_1 >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
a(param_1: 1);
'End' >> @>log;
}
}
Begin
`a` has been called!
1
End
app PeaceKeeper
{
fun a(@param_1)
{
'`a` (any) has been called!' >> @>log;
@param_1 >> @>log;
}
fun a(@param_1: (number | string))
{
'`a` (number | string) has been called!' >> @>log;
@param_1 >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
a(param_1: 1);
a(param_1: 'Hi');
'End' >> @>log;
}
}
Begin
`a` (number | string) has been called!
1
`a` (number | string) has been called!
Hi
End
app PeaceKeeper
{
fun a(@param_1)
{
'`a` (any) has been called!' >> @>log;
@param_1 >> @>log;
}
fun a(@param_1: number | string)
{
'`a` (number | string) has been called!' >> @>log;
@param_1 >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
a(param_1: 1);
a(param_1: 'Hi');
'End' >> @>log;
}
}
Begin
`a` (number | string) has been called!
1
`a` (number | string) has been called!
Hi
End
app PeaceKeeper
{
on Enter
{
fun SomeFun()
{
return 1;
}
'Begin' >> @>log;
SomeFun() >> @>log;
'End' >> @>log;
}
Function as a first order object
back to top
Read more about Function here.
Read more about Method here.
Read more about Anonymous function here.
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
@a = fun()
{
return 1;
};
@a() >> @>log;
'End' >> @>log;
}
}
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
fun()
{
return 1;
}() >> @>log;
'End' >> @>log;
}
}
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
@a = SomeFun();
@a() >> @>log;
'End' >> @>log;
}
fun SomeFun()
{
return fun()
{
return 1;
};
}
}
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
@a = OtherFun(SomeFun());
@a >> @>log;
'End' >> @>log;
}
fun SomeFun()
{
return fun()
{
return 1;
};
}
fun OtherFun(@param)
{
return @param();
}
}
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
@a = OtherFun(param: SomeFun());
@a >> @>log;
'End' >> @>log;
}
fun SomeFun()
{
return fun()
{
return 1;
};
}
fun OtherFun(@param)
{
return @param();
}
}
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
@a = OtherFun(@param: SomeFun());
@a >> @>log;
'End' >> @>log;
}
fun SomeFun()
{
return fun()
{
return 1;
};
}
fun OtherFun(@param)
{
return @param();
}
}
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
@a = OtherFun(fun()
{
return 1;
});
@a >> @>log;
'End' >> @>log;
}
fun OtherFun(@param)
{
return @param();
}
}
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
SomeFun()() >> @>log;
'End' >> @>log;
}
fun SomeFun()
{
return fun()
{
return 1;
};
}
}
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
SomeFun()() >> @>log;
'End' >> @>log;
}
fun SomeFun()
{
@a = 2;
return fun()
{
return @a + 1;
};
}
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
SomeFun(2)() >> @>log;
'End' >> @>log;
}
fun SomeFun(@a)
{
return fun()
{
return @a + 1;
};
}
}
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
OtherFun()() >> @>log;
'End' >> @>log;
}
fun OtherFun()
{
return SomeFun;
}
fun SomeFun()
{
return 1;
}
}"
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
OtherFun(SomeFun);
'End' >> @>log;
}
fun OtherFun(@fn)
{
@fn() >> @>log;
}
fun SomeFun()
{
return 1;
}
}
Idle actions
back to top
Read more here about Idle actions.
app PeaceKeeper
{
idle actions
{
go();
}
fun go()
{
'GO()' >> @>log;
wait 10;
}
}
app PeaceKeeper
{
idle actions
{
go()[: timeout=1 :];
}
fun go()
{
'GO()' >> @>log;
wait 10;
}
}
app PeaceKeeper
{
idle actions
{
{: >: { direction($x1,#@(place & color = green)) & $x1 = go(someone,self) } o: 1 :};
}
fun go(@direction)
{
'GO()' >> @>log;
@direction >> @>log;
wait 10;
}
}
app PeaceKeeper
{
idle actions
{
{: >: { direction($x1,#@(place & color = green)) & $x1 = go(someone,self) } o: 1 :}[: timeout=1 :];
}
fun go(@direction)
{
'GO()' >> @>log;
wait 10;
}
}
Action
back to top
Read more here about Action.
Read more here about Function call overloading.
Read more here about "complete action" statement.
Read more here about "break action" statement.
app PeaceKeeper
{
on Enter =>
{
'Begin' >> @>log;
Go();
'End' >> @>log;
}
}
action Go
{
on Enter =>
{
'Enter Go' >> @>log;
}
op () =>
{
'Begin Go' >> @>log;
'End Go' >> @>log;
}
on {: see(I, $x) :} ($x >> @x) =>
{
'on Fired' >> @>log;
@x >> @>log;
complete action;
}
}
Begin
Enter Go
Begin Go
End Go
End
app PeaceKeeper
{
on Enter =>
{
'Begin' >> @>log;
Go();
'End' >> @>log;
}
}
action Go
{
on Enter =>
{
'Enter Go' >> @>log;
}
on Leave
{
'Leave Go' >> @>log;
}
op () =>
{
'Begin Go' >> @>log;
'End Go' >> @>log;
}
}
Begin
Enter Go
Begin Go
End Go
Leave Go
End
app PeaceKeeper
{
on Enter =>
{
'Begin' >> @>log;
Go();
'End' >> @>log;
}
}
action Go
{
op () =>
{
'Begin Go' >> @>log;
@a = 10;
repeat
{
@a >> @>log;
@a = @a - 1;
a()[:on complete { complete action; } :];
if(@a > 5)
{
continue;
}
'End of while iteration' >> @>log;
break;
}
'End Go' >> @>log;
}
fun a() =>
{
'`a` has been called!' >> @>log;
}
}
Begin
Begin Go
10
`a` has been called!
End
Read more here about Annotation complete event.
State
back to top
Read more here about State.
app PeaceKeeper
{
set Idling as default state;
on Enter =>
{
'Begin' >> @>log;
'End' >> @>log;
}
}
states { Idling, Attacking }
state Idling
{
on Enter
{
'Begin Idling Enter' >> @>log;
'End Idling Enter' >> @>log;
}
}
state Attacking
{
enter on:
{: see(I, enemy) :}
leave on:
{: see(I, barrel) :}
on Enter
{
'Begin Attacking Enter' >> @>log;
'End Attacking Enter' >> @>log;
}
}
Begin
Begin Idling Enter
End
End Idling Enter
app PeaceKeeper
{
set Idling as state;
on Enter =>
{
'Begin' >> @>log;
'End' >> @>log;
}
}
state Idling
{
on Enter
{
'Begin Enter' >> @>log;
'End Enter' >> @>log;
}
}
Begin Enter
Begin
End Enter
End
app PeaceKeeper
{
set Idling as default state;
set Patrolling as state;
on Enter =>
{
'Begin' >> @>log;
'End' >> @>log;
}
}
state Idling
{
on Enter
{
'Begin Idling Enter' >> @>log;
'End Idling Enter' >> @>log;
}
}
state Patrolling
{
on Enter
{
'Begin Patrolling Enter' >> @>log;
set Idling as state;
'End Patrolling Enter' >> @>log;
}
}
Begin Patrolling Enter
Begin
Begin Idling Enter
End
End Idling Enter
app PeaceKeeper
{
set Patrolling as state;
}
state Idling
{
on Enter
{
'Begin Idling Enter' >> @>log;
'End Idling Enter' >> @>log;
}
}
state Patrolling
{
on Enter
{
'Begin Patrolling Enter' >> @>log;
set Idling as default state;
complete state;
'End Patrolling Enter' >> @>log;
}
}
Begin Patrolling Enter
Begin Idling Enter
End Idling Enter
app PeaceKeeper
{
set Idling as default state;
set Patrolling as state;
on Enter =>
{
'Begin' >> @>log;
'End' >> @>log;
}
on {: attack(I, enemy) :}
{
'D' >> @>log;
}
}
state Idling
{
on Enter
{
'Begin Idling Enter' >> @>log;
'End Idling Enter' >> @>log;
}
}
state Patrolling
{
on Enter
{
'Begin Patrolling Enter' >> @>log;
break state {: attack(I, enemy) :};
'End Patrolling Enter' >> @>log;
}
}
Begin
Begin Patrolling Enter
End
Begin Idling Enter
End Idling Enter
D
app PeaceKeeper
{
set Idling as default state;
set Patrolling as state;
on Enter =>
{
'Begin' >> @>log;
'End' >> @>log;
}
on {: attack(I, enemy) :}
{
'D' >> @>log;
}
}
state Idling
{
on Enter
{
'Begin Idling Enter' >> @>log;
'End Idling Enter' >> @>log;
}
}
state Patrolling
{
on Enter
{
'Begin Patrolling Enter' >> @>log;
break state;
'End Patrolling Enter' >> @>log;
}
}
Begin Patrolling Enter
Begin
End
Begin Idling Enter
End Idling Enter
app PeaceKeeper
{
set Idling as default state;
{: male(#Tom) :}
{: parent(#Piter, #Tom) :}
{: {son($x, $y)} -> { male($x) & parent($y, $x)} :}
}
state Idling
{
on Enter
{
'Begin Idling Enter' >> @>log;
select {: son($x, $y) :} >> @>log;
'End Idling Enter' >> @>log;
}
}
Begin Idling Enter
<yes>
$y = #piter; $x = #tom
End Idling Enter
app PeaceKeeper
{
set Idling as default state;
on Enter =>
{
'Begin' >> @>log;
select {: son($x, $y) :} >> @>log;
'End' >> @>log;
}
}
state Idling
{
{: male(#Tom) :}
{: parent(#Piter, #Tom) :}
{: {son($x, $y)} -> { male($x) & parent($y, $x)} :}
on Enter
{
'Begin Idling Enter' >> @>log;
'End Idling Enter' >> @>log;
}
}
Begin
Begin Idling Enter
End Idling Enter
<no>
End
app PeaceKeeper
{
set Idling as default state;
}
state Idling
{
on Enter
{
'Begin Idling Enter' >> @>log;
? {: bird ($x) :} >> @>log;
insert {: >: { bird (#1234) } :};
? {: bird ($x) :} >> @>log;
'End Idling Enter' >> @>log;
}
}
Begin Idling Enter
<no>
<yes>
$x = #1234
End Idling Enter
app PeaceKeeper
{
set Idling as default state;
set Patrolling as state;
on Enter =>
{
'Begin' >> @>log;
'End' >> @>log;
}
}
state Idling
{
on Enter
{
'Begin Idling Enter' >> @>log;
'End Idling Enter' >> @>log;
}
}
state Patrolling
{
on Enter
{
'Begin Patrolling Enter' >> @>log;
set Idling as state;
'End Patrolling Enter' >> @>log;
}
on Leave
{
'Begin Patrolling Leave' >> @>log;
'End Patrolling Leave' >> @>log;
}
}
Begin
Begin Patrolling Enter
End
Begin Patrolling Leave
Begin Idling Enter
End Patrolling Leave
End Idling Enter
Calling method
back to top
Read more here about Calling method.
You can see other examples here.
Synchronous
back to top
app PeaceKeeper
{
fun a() =>
{
'`a` has been called!' >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
a();
'End' >> @>log;
}
}
Begin
`a` has been called!
End
Asynchronous
back to top
Child asynchronous call
back to top
app PeaceKeeper
{
fun a() =>
{
'`a` has been called!' >> @>log;
}
on Enter =>
{
a~();
wait 1;
}
}
Independent asynchronous call
back to top
app PeaceKeeper
{
fun a() =>
{
'`a` has been called!' >> @>log;
}
on Enter =>
{
a~~();
}
}
Cancelation
back to top
app PeaceKeeper
{
fun a() =>
{
'`a` has been called!' >> @>log;
@a = 10;
while (@a > 0)
{
@a >> @>log;
@a = @a - 1;
}
'End `a`' >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
@a = a~~();
@a.cancel();
'End' >> @>log;
}
}
Begin
`a` has been called!
End
Timeout
back to top
app PeaceKeeper
{
fun a() =>
{
'`a` has been called!' >> @>log;
wait 10;
'End `a`' >> @>log;
}
fun b() =>
{
'`b` has been called!' >> @>log;
wait 10;
'End `b`' >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
@a = a~~()[: timeout = 1 :];
@b = b~~()[: timeout = 1 :];
wait @a, @b;
'End' >> @>log;
}
}
Begin
`a` has been called!
`b` has been called!
End
Calling host method
back to top
Read more here about Host.
In details writing a Host endpoint is described here.
Read more here about calling methods.
Synchronous
back to top
app PeaceKeeper is [0.5] exampleClass
{
on Enter =>
{
"Begin" >> @>log;
@@host.`go`(to: #@[25, 30]);
"End" >> @>log;
}
}
Asynchronous
back to top
app PeaceKeeper is [0.5] exampleClass
{
on Enter =>
{
"Begin" >> @>log;
@@host.`go`~~(to: #@[25, 30]);
"End" >> @>log;
}
}
Begin
End
methodName = 'go'
#020ED339-6313-459A-900D-92F809CEBDC5>>14-11-2022 20:09:18.90812 SymOntoClay.CLI.CLIRunHandler GenericCall LOG methodName = 'go'
isNamedParameters = True
#020ED339-6313-459A-900D-92F809CEBDC5>>14-11-2022 20:09:18.90986 SymOntoClay.CLI.CLIRunHandler GenericCall LOG isNamedParameters = True
namedParameters = {
"to": "#@[25, 30]"
}
#020ED339-6313-459A-900D-92F809CEBDC5>>14-11-2022 20:09:18.93094 SymOntoClay.CLI.CLIRunHandler GenericCall LOG namedParameters = {
"to": "#@[25, 30]"
}
positionedParameters = null
#020ED339-6313-459A-900D-92F809CEBDC5>>14-11-2022 20:09:18.93186 SymOntoClay.CLI.CLIRunHandler GenericCall LOG positionedParameters = null
Logic queries
back to top
Example 1
back to top
Read more about operator "select" here.
Read more about facts here.
Read more about logic rule here.
class exampleClass is human, [0.1] animal
{
{: male(#Tom) :}
{: parent(#Piter, #Tom) :}
{: {son($x, $y)} -> { male($x) & parent($y, $x)} :}
{: { love($x, $y) } -> { help($x, $y) } :}
}
app PeaceKeeper is [0.5] exampleClass
{
on Enter =>
{
"Begin" >> @>log;
select {: son($x, $y) :} >> @>log;
"End" >> @>log;
}
}
The result of this query:
Begin
<yes>
$y = #piter; $x = #tom
End
class exampleClass is human, [0.1] animal
{
{: male(#Tom) :}
{: parent(#Piter, #Tom) :}
{: {son($x, $y)} -> { male($x) & parent($y, $x)} :}
{: { love($x, $y) } -> { help($x, $y) } :}
}
app PeaceKeeper is [0.5] exampleClass
{
on Enter =>
{
"Begin" >> @>log;
? {: son($x, $y) :} >> @>log;
"End" >> @>log;
}
}
The result of this query:
Begin
<yes>
$y = #piter; $x = #tom
End
Example 2
back to top
Read more about operator "select" here.
Read more about facts here.
Read more about logic rule here.
Using inheritance in logic searching.
Read more here about inheritance in SymOntoClay DSL.
For set of facts:
{: can(bird, fly) :}
{: bird(#Alisa_12) :}
app PeaceKeeper
{
{: can(bird, fly) :}
{: bird(#Alisa_12) :}
on Enter =>
{
? {: can(#Alisa_12, $x) :} >> @>log;
}
}
The query:
{: can(#Alisa_12, $x) :}
returns:
The query:
{: can(#Alisa_12, fly) :}
app PeaceKeeper
{
{: can(bird, fly) :}
{: bird(#Alisa_12) :}
on Enter =>
{
? {: can(#Alisa_12, fly) :} >> @>log;
}
}
returns:
The query:
{: $z(#Alisa_12, $x) :}
app PeaceKeeper
{
{: can(bird, fly) :}
{: bird(#Alisa_12) :}
on Enter =>
{
? {: $z(#Alisa_12, $x) :} >> @>log;
}
}
returns:
The relationship beween concepts '#Alisa_12' and 'fly' is set by inheritance, not by direct fact or rule.
Example 3
back to top
Inserts fact {: >: { bird (#1234) } :}
into main storage of current NPC and returns inserted fact into expression's stack.
The fact is not displayed here.
Read more about operator "insert" here.
Read more about facts here.
Read more about logic rule here.
app PeaceKeeper is [0.5] exampleClass
{
on Enter =>
{
"Begin" >> @>log;
insert {: >: { bird (#1234) } :};
"End" >> @>log;
}
}
Example 4
back to top
app PeaceKeeper
{
{: animal(cat) :}
on Enter =>
{
select {: { cat is animal } :} >> @>log;
}
}
app PeaceKeeper
{
{: >: { animal(cat) } :}
on Enter =>
{
select {: cat is animal :} >> @>log;
}
}
app PeaceKeeper
{
{: animal(cat) :}
on Enter =>
{
select {: >: { cat is animal } :} >> @>log;
}
}
Example 5
back to top
linvar age for range (0, 150]
{
constraints:
for relation age;
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
app PeaceKeeper
{
{: age(#Tom, 15) :}
on Enter =>
{
select {: age(#Tom, `teenager`) :} >> @>log;
}
}
linvar age for range (0, 150]
{
constraints:
for relation age;
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
app PeaceKeeper
{
{: age(#Tom, 12) :}
on Enter =>
{
select {: age(#Tom, very `teenager`) :} >> @>log;
}
}
linvar age for range (0, 150]
{
constraints:
for relation age;
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
app PeaceKeeper
{
{: age(#Tom, 12) :}
on Enter =>
{
select {: age(#Tom, very teenager) :} >> @>log;
}
}
linvar age for range (0, 150]
{
constraints:
for relation age;
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
app PeaceKeeper
{
{: age(#Tom, 12) :}
on Enter =>
{
select {: age(#Tom, `very` `teenager`) :} >> @>log;
}
}
linvar age for range (0, 150]
{
constraints:
for relation age;
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
app PeaceKeeper
{
{: age(#Tom, very `teenager`) :}
on Enter =>
{
select {: age(#Tom, 12) :} >> @>log;
}
}
linvar age for range (0, 150]
{
constraints:
for relation age;
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
app PeaceKeeper
{
{: age(#Tom, `teenager`) :}
on Enter =>
{
select {: age(#Tom, 12) :} >> @>log;
}
}
Example 6
back to top
app PeaceKeeper
{
{: >: {distance($x, $y)} -> { distance(I, $x, $y) } :}
{: age(#Tom, 50) :}
{: distance(I, #Tom, 12) :}
on Enter =>
{
select {: age(#Tom, $x) & distance(#Tom, $y) & $x is not $y :} >> @>log;
}
}
Example 7
back to top
app PeaceKeeper
{
{: >: {distance($x, $y)} -> { distance(I, $x, $y) } :}
{: distance(I, #Tom, 12) :}
on Enter =>
{
select {: distance(#Tom, $x) & $x is 12 :} >> @>log;
}
}
Example 8
back to top
app PeaceKeeper
{
{: >: {distance($x, $y)} -> { distance(I, $x, $y) } :}
{: distance(I, #Tom, 50) :}
on Enter =>
{
select {: distance(#Tom, $x) & $x > 5 :} >> @>log;
}
}
linvar age for range (0, 150]
{
constraints:
for relation age;
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
app PeaceKeeper
{
{: age(#Tom, 50) :}
on Enter =>
{
select {: age(#Tom, $x) & $x > `teenager` :} >> @>log;
}
}
linvar age for range (0, 150]
{
constraints:
for relation age;
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
app PeaceKeeper
{
{: age(#Tom, 50) :}
on Enter =>
{
select {: age(#Tom, $x) & $x > very `teenager` :} >> @>log;
}
}
Example 9
back to top
app PeaceKeeper
{
{: >: {distance($x, $y)} -> { distance(I, $x, $y) } :}
{: distance(I, #Tom, 50) :}
on Enter =>
{
select {: distance(#Tom, $x) & $x >= 5 :} >> @>log;
}
}
Example 10
back to top
app PeaceKeeper
{
{: >: {distance($x, $y)} -> { distance(I, $x, $y) } :}
{: distance(I, #Tom, 4) :}
on Enter =>
{
select {: distance(#Tom, $x) & $x < 5 :} >> @>log;
}
}
Example 11
back to top
app PeaceKeeper
{
{: >: {distance($x, $y)} -> { distance(I, $x, $y) } :}
{: distance(I, #Tom, 5) :}
on Enter =>
{
select {: distance(#Tom, $x) & $x <= 5 :} >> @>log;
}
}
Example 12
back to top
app PeaceKeeper
{
{: barrel(#a) :}
{: see(I, #a) :}
on Enter =>
{
select {: see(I, $x) & barrel($x) & !focus(I, friend) :} >> @>log;
}
}
Imperative logic operators
back to top
Read more about Imperative logic operators here and here.
app PeaceKeeper
{
on Enter =>
{
'Begin' >> @>log;
@a = 3;
if(@a <= 0 | @a is 3 | @a > 5)
{
'Yes!' >> @>log;
} else {
'Else Yes!' >> @>log;
}
'End' >> @>log;
}
}
linvar age for range (0, 150]
{
terms:
`teenager` = Trapezoid(10, 12, 17, 20);
}
app PeaceKeeper
{
on Enter =>
{
'Begin' >> @>log;
@a = 16;
if(@a <= teenager)
{
'Yes!' >> @>log;
} else {
'Else Yes!' >> @>log;
}
'End' >> @>log;
}
}
Arithmetic operators
back to top
Read more about Arithmetic operators here.
app PeaceKeeper
{
private:
on Enter =>
{
'Begin' >> @>log;
1 + 1 >> @>log;
'End' >> @>log;
}
}
app PeaceKeeper
{
private:
@a = 2;
on Enter =>
{
@b = 3;
'Begin' >> @>log;
@a + @b >> @>log;
'End' >> @>log;
}
}
app PeaceKeeper
{
private:
on Enter =>
{
'Begin' >> @>log;
1 + NULL >> @>log;
'End' >> @>log;
}
}
app PeaceKeeper
{
private:
on Enter =>
{
'Begin' >> @>log;
1 + 'Hi' >> @>log;
'End' >> @>log;
}
}
app PeaceKeeper
{
private:
on Enter =>
{
'Begin' >> @>log;
3 - 1 >> @>log;
'End' >> @>log;
}
}
app PeaceKeeper
{
private:
on Enter =>
{
'Begin' >> @>log;
3 * 4 >> @>log;
'End' >> @>log;
}
}
app PeaceKeeper
{
private:
on Enter =>
{
'Begin' >> @>log;
12 / 4 >> @>log;
'End' >> @>log;
}
}
app PeaceKeeper
{
private:
on Enter =>
{
'Begin' >> @>log;
12 / 0 >> @>log;
'End' >> @>log;
}
}
app PeaceKeeper
{
on Enter =>
{
'Begin' >> @>log;
(3 + 5) * 2 >> @>log;
'End' >> @>log;
}
}
app PeaceKeeper
{
private:
on Enter =>
{
'Begin' >> @>log;
@a = 2;
2 * -@a >> @>log;
'End' >> @>log;
}
}
app PeaceKeeper
{
private:
on Enter =>
{
'Begin' >> @>log;
@a = -2;
2 * -@a >> @>log;
'End' >> @>log;
}
}
app PeaceKeeper
{
private:
on Enter =>
{
'Begin' >> @>log;
@a = -2;
2 * +@a >> @>log;
'End' >> @>log;
}
}
app PeaceKeeper
{
private:
on Enter =>
{
'Begin' >> @>log;
@a = 2;
2 * +@a >> @>log;
'End' >> @>log;
}
}
Operator "new"
back to top
class class1
{
@b = 1;
}
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
@a = new class1;
@a.@b >> @>log;
'End' >> @>log;
}
}
class class1
{
@b = 1;
}
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
@c = class1;
@a = new @c;
@a.@b >> @>log;
'End' >> @>log;
}
}
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
@c = {
@b = 1;
};
@a = new @c;
@a.@b >> @>log;
'End' >> @>log;
}
}
class class1
{
@b = 1;
}
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
OtherFun(param: new class1);
'End' >> @>log;
}
fun OtherFun(@param)
{
@param.@b >> @>log;
}
}
class cls0
{
ctor(@param: string)
{
'Begin ctor of cls0' >> @>log;
@param >> @>log;
@b >> @>log;
'End ctor of cls0' >> @>log;
}
private:
@b = 0;
}
class cls1 is cls0
{
ctor(@param: string)
: cls0('Cool!')
{
'Begin ctor of cls1' >> @>log;
@param >> @>log;
@b >> @>log;
'End ctor of cls1' >> @>log;
}
private:
@b = 1;
}
app PeaceKeeper
{
on Enter
{
'Begin' >> @>log;
@a = new cls1('Hi!');
@a.@b >> @>log;
'End' >> @>log;
}
}
Begin
Begin ctor of cls0
Cool!
0
End ctor of cls0
Begin ctor of cls1
Hi!
1
End ctor of cls1
1
End
Read more about "new" statement here.
Logic сonditional triggers
back to top
In this example trigger fires and writes "Logic condition fired!!!!" after insert fact.
In Unity scene facts are provided by perception channels.
Read more about Logic сonditional triggers here.
app MyNPC
{
{: barrel(#`Barel 1`) :}
on Enter =>
{
"Begin" >> @>log;
insert {: see(I, #`Barel 1`) :};
"End" >> @>log;
}
on {: see(I, barrel) :} =>
{
"Logic condition fired!!!!" >> @>log;
}
}
Begin
End
Logic condition fired!!!!
app PeaceKeeper
{
@a = #`gun 1`;
on Enter =>
{
'Begin' >> @>log;
insert {: see(I, @a) :};
}
on {: see(I, @a) :} =>
{
'D' >> @>log;
}
}
This trigger binds captured in logic variable value with imperative variable.
Read more about binding variables here.
app PeaceKeeper
{
{: barrel(#a) :}
{: see(I, #a) :}
on {: see(I, $x) & barrel($x) & !focus(I, friend) :} ($x >> @x) =>
{
@x >> @>log;
}
}
"each" timer
back to top
Read more about "each" timer here.
app PeaceKeeper
{
on each 1
{
'Run!!!' >> @>log;
}
}
"once" timer
back to top
Read more about "once" timer here.
app PeaceKeeper
{
on once 1
{
'Run!!!' >> @>log;
}
}
Error handling
back to top
Read more about error handling here.
app PeaceKeeper
{
fun a(@param_1) =>
{
'`a` has been called!' >> @>log;
@param_1 >> @>log;
error {: see(I, #a) :};
'End of `a`' >> @>log;
}
on Enter =>
{
try
{
'Begin' >> @>log;
a(param_1: 1);
'End' >> @>log;
}
catch
{
'catch' >> @>log;
}
catch(@e)
{
'catch(@e)' >> @>log;
@e >> @>log;
}
catch(@e) where {: hit(enemy, I) :}
{
'catch(@e) where {: hit(enemy, I) :}' >> @>log;
}
catch(@e) where {: see(I, $x) :}
{
'catch(@e) where {: see(I, $x) :}' >> @>log;
@e >> @>log;
}
else
{
'else' >> @>log;
}
ensure
{
'ensure' >> @>log;
}
'End of `Enter`' >> @>log;
}
}
Begin
`a` has been called!
1
catch(@e) where {: see(I, $x) :}
ERROR {: #^`93666682-93fd-44bf-870a-2d3056703be4` >: { see(i,#a) } :}
ensure
End of `Enter`
app PeaceKeeper
{
fun a(@param_1) =>
{
'`a` has been called!' >> @>log;
@param_1 >> @>log;
error {: see(I, #a) :};
'End of `a`' >> @>log;
}
on Enter =>
{
try
{
'Begin' >> @>log;
a(param_1: 1);
'End' >> @>log;
}
catch
{
'catch' >> @>log;
}
catch(@e)
{
'catch(@e)' >> @>log;
@e >> @>log;
}
catch(@e) where {: hit(enemy, I) :}
{
'catch(@e) where {: hit(enemy, I) :}' >> @>log;
}
catch(@e) where {: see(I, $x) :}
{
'catch(@e) where {: see(I, $x) :}' >> @>log;
@e >> @>log;
}
else
{
'else' >> @>log;
}
ensure
{
'ensure' >> @>log;
}
'End of `Enter`' >> @>log;
}
on {: see(I, $x) :} ($x >> @x) =>
{
'on Fired' >> @>log;
@x >> @>log;
}
}
Begin
`a` has been called!
1
catch(@e) where {: see(I, $x) :}
on Fired
ERROR {: #^`622a951d-b377-482a-b081-b227706ce6de` >: { see(i,#a) } :}
#a
ensure
End of `Enter`
app PeaceKeeper
{
fun a(@param_1) =>
{
'`a` has been called!' >> @>log;
@param_1 >> @>log;
error {: see(I, #a) :};
'End of `a`' >> @>log;
}
on Enter =>
{
try
{
'Begin' >> @>log;
a(param_1: 1);
'End' >> @>log;
}
catch
{
'catch' >> @>log;
}
'End of `Enter`' >> @>log;
}
}
Begin
`a` has been called!
1
catch
End of `Enter`
app PeaceKeeper
{
fun a(@param_1) =>
{
'`a` has been called!' >> @>log;
@param_1 >> @>log;
error {: see(I, #a) :};
'End of `a`' >> @>log;
}
on Enter =>
{
try
{
'Begin' >> @>log;
a(param_1: 1);
'End' >> @>log;
}
catch
{
'catch' >> @>log;
}
else
{
'else' >> @>log;
}
'End of `Enter`' >> @>log;
}
}
Begin
`a` has been called!
1
catch
End of `Enter`
app PeaceKeeper
{
fun a(@param_1) =>
{
'`a` has been called!' >> @>log;
@param_1 >> @>log;
error {: see(I, #a) :};
'End of `a`' >> @>log;
}
on Enter =>
{
try
{
'Begin' >> @>log;
a(param_1: 1);
'End' >> @>log;
}
catch
{
'catch' >> @>log;
}
else
{
'else' >> @>log;
}
ensure
{
'ensure' >> @>log;
}
'End of `Enter`' >> @>log;
}
}
Begin
`a` has been called!
1
catch
ensure
End of `Enter`
app PeaceKeeper
{
fun a(@param_1) =>
{
'`a` has been called!' >> @>log;
@param_1 >> @>log;
error {: see(I, #a) :};
'End of `a`' >> @>log;
}
on Enter =>
{
try
{
'Begin' >> @>log;
a(param_1: 1);
'End' >> @>log;
}
'End of `Enter`' >> @>log;
}
}
Begin
`a` has been called!
1
End of `Enter`
app PeaceKeeper
{
on Enter =>
{
try
{
'Begin' >> @>log;
error {: see(I, #a) :};
'End' >> @>log;
}
else
{
'else' >> @>log;
}
'End of `Enter`' >> @>log;
}
}
app PeaceKeeper
{
on Enter =>
{
try
{
'Begin' >> @>log;
error {: see(I, #a) :};
'End' >> @>log;
}
ensure
{
'ensure' >> @>log;
}
'End of `Enter`' >> @>log;
}
}
Begin
ensure
End of `Enter`
app PeaceKeeper
{
on Enter =>
{
try
{
'Begin' >> @>log;
error {: see(I, #a) :};
'End' >> @>log;
}
else
{
'else' >> @>log;
}
ensure
{
'ensure' >> @>log;
}
'End of `Enter`' >> @>log;
}
}
Begin
ensure
End of `Enter`
"repeat" statement
back to top
Read more about "repeat" statement here.
app PeaceKeeper
{
on Enter =>
{
'Begin' >> @>log;
@a = 10;
repeat
{
@a >> @>log;
@a = @a - 1;
if(@a > 5)
{
continue;
}
'End of while iteration' >> @>log;
break;
}
'End' >> @>log;
}
}
Begin
10
9
8
7
6
End of while iteration
End
"while" statement
back to top
Read more about "while" statement here.
app PeaceKeeper
{
on Enter =>
{
'Begin' >> @>log;
@a = 10;
while (@a > 0)
{
@a >> @>log;
@a = @a - 1;
}
'End' >> @>log;
}
}
"return" statement
back to top
Read more about "return" statement here.
app PeaceKeeper
{
fun a() =>
{
'`a` has been called!' >> @>log;
return;
'`a` has been ended!' >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
a();
'End' >> @>log;
}
}
Begin
`a` has been called!
End
app PeaceKeeper
{
fun a() =>
{
'`a` has been called!' >> @>log;
return;
'`a` has been ended!' >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
a() >> @>log;
'End' >> @>log;
}
}
Begin
`a` has been called!
NULL
End
app PeaceKeeper
{
fun a() =>
{
'`a` has been called!' >> @>log;
return 1;
'`a` has been ended!' >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
a() >> @>log;
'End' >> @>log;
}
}
Begin
`a` has been called!
1
End
"if-elif-else" statement
back to top
Read more about "if-elif-else" statement here.
app PeaceKeeper
{
on Enter =>
{
'Begin' >> @>log;
@a = 1;
if(@a)
{
'Yes!' >> @>log;
}
'End' >> @>log;
}
}
app PeaceKeeper
{
{: >: { see(I, #`Barel 1`) } :}
on Enter =>
{
'Begin' >> @>log;
if({: >: { see(I, #`Barel 1`) } :})
{
'Yes!' >> @>log;
}
'End' >> @>log;
}
}
app PeaceKeeper
{
{: >: { see(I, #`Barel 1`) } :}
on Enter =>
{
'Begin' >> @>log;
if({: >: { see(I, #`Barel 1`) } :})
{
'Yes!' >> @>log;
} else {
'Else Yes!' >> @>log;
}
'End' >> @>log;
}
}
app PeaceKeeper
{
{: >: { see(I, #`Barel 0`) } :}
on Enter =>
{
'Begin' >> @>log;
if({: >: { see(I, #`Barel 0`) } :})
{
'Yes!' >> @>log;
} elif ({: >: { see(I, #`Barel 1`) } :}) {
'Elif 1 Yes!' >> @>log;
}
'End' >> @>log;
}
}
app PeaceKeeper
{
{: >: { see(I, #`Barel 3`) } :}
on Enter =>
{
'Begin' >> @>log;
if({: >: { see(I, #`Barel 0`) } :})
{
'Yes!' >> @>log;
} elif ({: >: { see(I, #`Barel 1`) } :}) {
'Elif 1 Yes!' >> @>log;
}elif ({: >: { see(I, #`Barel 2`) } :}) {
'Elif 2 Yes!' >> @>log;
}else{
'Else Yes!' >> @>log;
}
'End' >> @>log;
}
}
"continue" loop statement
back to top
Read more about "continue" loop statement here.
app PeaceKeeper
{
on Enter =>
{
'Begin' >> @>log;
@a = 10;
repeat
{
@a >> @>log;
@a = @a - 1;
if(@a > 5)
{
continue;
}
'End of while iteration' >> @>log;
break;
}
'End' >> @>log;
}
}
Begin
10
9
8
7
6
End of while iteration
End
"break" loop statement
back to top
Read more about "break" loop statement here.
app PeaceKeeper
{
on Enter =>
{
'Begin' >> @>log;
@a = 10;
while (@a > 0)
{
@a >> @>log;
@a = @a - 1;
if(@a > 5)
{
break;
}
}
'End' >> @>log;
}
}
"exec" statement
back to top
Read more about "exec" statement here.
app PeaceKeeper
{
on Enter => {
exec {: >: { direction($x1,#@{: >: { color($_,$x1) & place($_) & green($x1) } :}) & $x1 = go(someone,self) } o: 1 :};
}
fun go(@direction)
{
'go!!!!' >> @>log;
@direction >> @>log;
}
}
go!!!!
#@{: #^`3e55c913-f4fc-4102-ab67-4dab1d228207` >: { color($_,$x1) & place($_) & green($x1) } :}
"wait" statement
back to top
app PeaceKeeper
{
fun a() =>
{
'`a` has been called!' >> @>log;
}
on Enter =>
{
a~();
wait 1;
}
}
app PeaceKeeper
{
fun a() =>
{
'`a` has been called!' >> @>log;
@a = 10;
while (@a > 0)
{
@a >> @>log;
@a = @a - 1;
}
'End `a`' >> @>log;
}
fun b() =>
{
'`b` has been called!' >> @>log;
@a = 10;
while (@a > 0)
{
@a >> @>log;
@a = @a - 1;
}
'End `b`' >> @>log;
}
on Enter =>
{
'Begin' >> @>log;
@a = a~();
@b = b~();
wait @a, @b;
'End' >> @>log;
}
}
Begin
`a` has been called!
`b` has been called!
10
10
9
9
8
8
7
7
6
6
5
5
4
4
3
3
2
2
1
1
End `b`
End `a`
End