div

24 views
Skip to first unread message

oja...@gmail.com

unread,
Dec 1, 2015, 7:35:57 PM12/1/15
to Brahms Forum
I was looking in the language definition and saw that 'div' was a keyword. I'm pretty sure its some kind of relational operator, but is there any documentation of what it means or how to use it?

Maarten Gmail

unread,
Dec 1, 2015, 10:37:25 PM12/1/15
to brahms...@googlegroups.com
Ojaneeo,

Div is the “div” operator, with a definition of the modulus, remainder, or integer division, operator:




Maarten.

On Dec 1, 2015, at 4:35 PM, oja...@gmail.com wrote:

I was looking in the language definition and saw that 'div' was a keyword. I'm pretty sure its some kind of relational operator, but is there any documentation of what it means or how to use it?

--
You received this message because you are subscribed to the Google Groups "Brahms Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brahms-forum...@googlegroups.com.
To post to this group, send email to brahms...@googlegroups.com.
Visit this group at http://groups.google.com/group/brahms-forum.
For more options, visit https://groups.google.com/d/optout.

oja...@gmail.com

unread,
Dec 2, 2015, 1:25:39 PM12/2/15
to Brahms Forum
Thanks, Maarten.
Using it as an operator for a precondition, the Brahms compiler seems to want <operand> div <operand> is <truth value>
Do you know why this might be the case? 
When I try to use integers as the operands, it gives me the message:


Illegal type on left hand side in relational comparison 'int'



Am I missing something?

Jane

Maarten Sierhuis

unread,
Dec 2, 2015, 4:25:03 PM12/2/15
to brahms...@googlegroups.com
Jane,

Yes, I guess you are missing something. "div" is NOT a precondition evaluation-operator, if that's how you are using it. It is a term part of an expression. An expression can be a left-hand or right-hand-side of a precondition with an evaluation-operator in the middle.

Study the BNF for a precondition:


Can you provide an example of what you're trying to do?

Maarten.

oja...@gmail.com

unread,
Dec 3, 2015, 1:45:36 PM12/3/15
to Brahms Forum
Definitely! I'm just trying to get familiar with the language, so my example is pretty trivial:

agent DivTest {

attributes:
int x;
int y;
initial_beliefs:
(current.x = 10);
(current.y = 4);

activities:
primitive_activity wait()
{
max_duration: 10;
}
java println(string message) { 
class: "brahms.base.system.PrintlnActivity"; 
}
java printBelief(Concept aboutConcept, string aboutAttribute, string aboutAttributeType) {
class: "brahms.base.system.PrintBeliefActivity";
}
workframes:
workframe wf_divTest
{
repeat: true;
when (
knownval(current.x div current.y  = 2)  //With this, the compiler doesn't like '=', and wants 'is' instead
                                        //If I change it to 'is' then it wants '2' to be 'unknown' 'true' or 'false'
                                        //If I change the '2' to one of those values, it tells me "Illegal type on left hand side in relational comparison 'int'
                                        //which is why I thought 'div' was a relational operator initially
)
do {
wait();
println("BEFORE:   ");
printBelief(current, "x", "attribute");
printBelief(current, "y", "attribute");
conclude((current.x = current.x + 1));
conclude((current.y = current.y + 1));
println("AFTER:     ");
printBelief(current, "x", "attribute");
printBelief(current, "y", "attribute");

Maarten Sierhuis

unread,
Dec 4, 2015, 8:54:48 PM12/4/15
to brahms...@googlegroups.com
Hi Jane,

I did a quick test, and it seems indeed that the compiler has trouble with the div operator in preconditions. I never use any of Brahms’ math operators in preconditions, since dealing with assignments and evaluations in a precondition is problematic. You can do things easily in the body of a workframe. Here is a simple solution (I use an integer division):

/**
* @author sierhuis
* @version $Revision:$ $Date:$ $Author:$
*/
agent DivTest memberof SystemGroup {
attributes:
int x;
int y;
int z;

initial_beliefs:
(current.x = 10);
(current.y = 4);
(current.z = 2);

workframes:
workframe wf_divTest
{
repeat: true;
when ((current.z = 2))
do {
println("BEFORE: ");
printBelief(current, "z", "attribute");
printBelief(current, "x", "attribute");
printBelief(current, "y", "attribute");
conclude((current.x = current.x + 1));
conclude((current.y = current.y + 1));
conclude((current.z = current.x / current.y));
println("AFTER: ");
printBelief(current, "x", "attribute");
printBelief(current, "y", "attribute");
printBelief(current, "z", "attribute");
}
}
}


Here is another solution (without z as a belief) :

/**
* @author sierhuis
* @version $Revision:$ $Date:$ $Author:$
*/
agent DivTest memberof SystemGroup {
attributes:
int x;
int y;

initial_beliefs:
(current.x = 10);
(current.y = 4);

workframes:
workframe wf_divTest
{
repeat: true;
variables:
forone(int) x;
forone(int) y;
forone(int) z;
when ((x = current.x) and
(y = current.y) and
(z = x / y) and
(z = 2))
do {
println("BEFORE: ");
printBelief(current, "x", "attribute");
printBelief(current, "y", "attribute”);
println_n(“z = %1”, z);
conclude((current.x = current.x + 1));
conclude((current.y = current.y + 1));
println("AFTER: ");
printBelief(current, "x", "attribute");
printBelief(current, "y", "attribute");
println_n(“z = %1”, z);
}
}
}

Maarten Sierhuis, Ph.D.
Founder & CTO, Ejenta

oja...@gmail.com

unread,
Dec 7, 2015, 3:57:08 PM12/7/15
to Brahms Forum
Thanks for the solution, Maarten!
Reply all
Reply to author
Forward
0 new messages