Skip to content

Instantly share code, notes, and snippets.

@snay2
Created February 27, 2012 18:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snay2/1925904 to your computer and use it in GitHub Desktop.
Save snay2/1925904 to your computer and use it in GitHub Desktop.
Simple example for using arrays in an entity variable in KRL
ruleset a163x156 {
meta {
name "Arrays"
description <<
Some experiments using arrays in KRL
>>
author "Steve Nay"
logging on
}
dispatch { }
global { }
rule framework {
select when pageview ".*"
pre {
msg = <<
This is the current list of items:
<div id="items"></div>
Add a new one:
<form id="array-item-add">
<input type="text" name="item" />
<input type="submit" />
</form>
Or, reset the list: <input type="button" id="reset" value="Reset" />
>>;
}
{
notify("Experimenting with arrays", msg) with sticky=true;
watch("#array-item-add", "submit");
watch("#reset", "click");
}
}
rule populate {
select when pageview ".*"
foreach ent:myarray setting (item)
append("#items", "#{item}<br />");
}
rule item_add {
select when web submit "array-item-add"
pre {
item = event:param("item");
item_array = ["#{item}"];
new_array = item_array.union(ent:myarray);
msg = <<
Added item "#{item}".
>>;
}
notify("Experimenting with arrays", msg);
fired {
set ent:myarray new_array;
}
}
rule reset {
select when web click "reset"
fired {
set ent:myarray [];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment