Page Menu
Home
Xreate
Search
Configure Global Search
Log In
Docs
Questions
Repository
Issues
Patches
Internal API
Files
F3998424
test2.xreate
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Jul 9, 12:05 AM
Size
2 KB
Mime Type
text/plain
Expires
Sat, Jul 11, 12:05 AM (1 d, 8 h)
Engine
blob
Format
Raw Data
Handle
272892
Attached To
rXR Xreate
test2.xreate
View Options
import raw ("scripts/latereasoning/context-v1.lp").
import raw ("scripts/latereasoning/test2.assembly.lp").
Annotation = type variant {
Num:: int,
String:: string,
Func:: {name::string, arguments::[Annotation]}
}.
FnControl = type variant {
Variant1, Variant2
}.
main = function:: int; entry {
funcA() + funcB() :: int
}
funcA = function::int{
context:: variant1.
testedFunc(prepareCtrlArg("testedFunc", intrinsic query_scope()))
}
funcB = function::int {
context:: variant2.
testedFunc(prepareCtrlArg("testedFunc", intrinsic query_scope()))
}
testedFunc = function(ctrl::FnControl):: int {
context:: kleo_manual_demand(funcC).
switch variant(ctrl)::int
case(Variant1){context:: callguard(variant1). funcC():: int; dfa_polym(cntxt)}
case(Variant2){context:: callguard(variant2). funcC():: int; dfa_polym(cntxt)}
}
guard:: variant1 {
funcC = function:: int {1}
}
guard:: variant2 {
funcC = function:: int {2}
}
selectSecond = function (db:: [Annotation], argFirst::Annotation):: Annotation; interpretation(force) {
resultWrong = String("wrong")::Annotation.
loop fold(db->entry:: Annotation, resultWrong->result):: Annotation{
switch variant(entry):: Annotation
case (Num) {resultWrong}
case (String) {resultWrong}
case (Func) {
if(entry["arguments"][0] == argFirst)::Annotation
{entry["arguments"][1]::Annotation; break}
else {result}
}
}
}
selectThird = function (db:: [Annotation], argFirst::Annotation, argSecond:: Annotation):: Annotation; interpretation(force){
resultWrong = String("wrong")::Annotation.
loop fold(db->entry:: Annotation, resultWrong->result):: Annotation{
switch variant(entry):: Annotation
case (Num) {resultWrong}
case (String) {resultWrong}
case (Func) {
if(entry["arguments"][0] == argFirst)::Annotation{
if (entry["arguments"][1] == argSecond):: Annotation{
entry["arguments"][2]:: Annotation; break
} else {result}
} else {result}
}
}
}
prepareCtrlArg = function(fnName:: string; interpretation(force),
scope:: Annotation; interpretation(force))
:: FnControl {
demandsDb = intrinsic query("kleo_fn_demand")::[Annotation].
decisionsDb = intrinsic query("kleo_scope_decision")::[Annotation].
demandKey = selectSecond(demandsDb, Func({name = fnName, arguments = []})):: Annotation.
decisionKey = Func({name="kleo_arg", arguments=[demandKey]}):: Annotation.
decision = selectThird(decisionsDb, scope, decisionKey)::Annotation.
switch variant(decision):: FnControl
case (Num) {Variant1()}
case (String) {Variant1()}
case (Func) {
switch(decision["name"]):: FnControl
case("variant1") {Variant1()}
case("variant2") {Variant2()}
case default {Variant1()}
}
}
Event Timeline
Log In to Comment