1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Multi-field (Multislot) Pattern Examples - CLIPS-inspired
// This file demonstrates multi-field variable patterns in GRL
// Run with: cargo run --example multifield_grl_demo
// Rule 1: Collect all items from an order
rule "CollectOrderItems" salience 100 {
when
Order.status == "pending" &&
Order.items $?all_items
then
Log("Processing order with items");
Order.status = "processing";
}
// Rule 2: Check if product has specific tag
rule "CheckElectronicsTag" salience 90 no-loop {
when
Product.tags contains "electronics"
then
Log("Product is electronics");
Product.category = "tech";
}
// Rule 3: Validate order has items
rule "ValidateOrderNotEmpty" salience 80 no-loop {
when
Order.items count > 0
then
Log("Order has items");
Order.valid = true;
}
// Rule 4: Process first item in queue
rule "ProcessFirstTask" salience 70 no-loop {
when
Queue.tasks not_empty &&
Queue.tasks first $first_task
then
Log("Processing first task");
Queue.current = $first_task;
}
// Rule 5: Check minimum item count
rule "BulkOrder" salience 60 no-loop {
when
Order.items count >= 5
then
Log("Bulk order detected");
Order.discount = 0.15;
}
// Rule 6: Tag-based routing
rule "RouteByTag" salience 50 no-loop {
when
Product.tags contains "sale"
then
Product.route = "promotional";
}
// Rule 7: Access last item
rule "ProcessLastItem" salience 40 no-loop {
when
Order.items last $last_item
then
Log("Last item in order");
Order.last_item = $last_item;
}
// Rule 8: Check empty array
rule "EmptyCart" salience 30 no-loop {
when
ShoppingCart.items empty
then
Log("Cart is empty");
ShoppingCart.status = "empty";
}
// Rule 9: Multiple conditions with multifield
rule "PremiumElectronicsOrder" salience 20 {
when
Order.items count > 3 &&
Product.tags contains "electronics" &&
Product.tags contains "premium"
then
Log("Premium electronics bulk order");
Order.priority = "high";
Order.discount = 0.20;
}
// Rule 10: Collect and count pattern
rule "InventoryCheck" salience 10 no-loop {
when
Inventory.items $?all_items &&
Inventory.items count < 10
then
Log("Low inventory alert");
Inventory.alert = "low_stock";
}