Praxis 101: Bonus calculation rule | Scribe

Praxis 101: Bonus calculation rule

  • Torbjörn Josefsson |
  • 0 step |
  • 10 minutes
  • ToblotronToblotron
Navigate to [https://toblotron.com/praxis/0.1.0/](https://toblotron.com/praxis/0.1.0/)
As soon as you get to the Praxis IDE you will see a new, empty model.
Let's give our model a name, and create a rules-page
To create our first rule, we drag out a Predicate shape from the palette Click here.
We'll name it "bonus", and fill in the first two arguments with "Age" and "Employed"
Select the field "Rule name", and type "bonus [[tab]] [[tab]] Age [[tab]] Employed"
Click "+" to add an argument - this will be the output argument, and we'll name it "Bonus" Click "Ok"
In Prolog (and Praxis), a word starting with an upper-case letter is a Variable, and these can hold Any value
Click on the background to de-select the shape, so we can see the Palette again
The new rule, "bonus/3" (/3 means it has 3 arguments) can already be used - but it doesn't do anything yet, so let's start adding Conditions that will decide if the rule succeeds, and in that case what happens.
Now we are going to work with Formula shapes, to make our decisions. Type "Employed [[tab]] < [[tab]] 5" Click "Ok"
Copy the shape, paste it, and move the copy where it should be Mark the shape/ shapes you want to copy Press [[ctrl]] + [[c]] Press [[ctrl]] + [[v]]
In this shape we want to allow for the case when Employed is More than 5 years, instead of less. Type ">" Click "Ok" Click outside shape to see Palette.
Drag out a Connection shape from the palette, and connect the shapes to it Connect by dragging from bottom-circles to top-circles.
Continue building the decision-tree, in the same fashion
Now we have completed an entire branch of our tree - if Employed > 5 and Age > 40, Bonus will be 100!
Now we must complete the other branch, which will contain more decisions
Ok - I just remembered I have to allow for the value 5 of Employed - as it is now, all values but 5 will allow the rule to proceed, but not 5 :)
Enter ">=" instead of ">" here, and we're done
Now we must assign a value to Bonus in each of the remaining branches - otherwise we won't have any answer in those cases Select the Formula shape, and click "+" to add a calculation-row Click this text field. Type "Bonus [[tab]] = [[tab]] 200" Click "Ok"
Want to make guides like this in seconds? Yes, it's really that fast.
This Scribe is in tip-top shape!Leave feedback if there are any issues with this Scribe