query-student-scores.taq

$ java -jar taq.jar query-student-scores

Running query marks in global scope 
student_marks(report=George English:b+ Math:b- History:a-)
student_marks(report=Sarah English:c+ Math:a History:b+)
student_marks(report=Amy English:b Math:a- History:e+)

Description

query-student-scores.taq demonstrates making a query to a flow using a function call operation. The “report” flow belongs to the “school” scope and is designed to take 3 integer numbers, convert each one into a subject + alpha mark axiom and return an axiom list result in a term named “subjects”. The term which is exported is an axiom list declaration

list<axiom> subjects

The following terms populate the iist and are made private as, given their inclusion in the subjects list, they are redundant. Notice that only the first list concatenation term needs to be explicitly marked as private to make all three private.

The operation to run the query to the template looks like a function call, The fact it performs a query is hidden, but there is no disguising the fact that a flow only returns a term list. When the list contains only a single term, as is the case here, it makes sense to reference the term immediately after the function call returns

cursor<axiom> subjects =

school.report(english, maths, history)->subjects

This invokes a query to the “report” flow with parameters “english”, “maths” and “history” and the “subjects” result is extracted from the returned term list. You will notice that the terms of the “report” template scope align with the parameters of the call.


axiom list grades
(student, english, maths, history)
{"George", 15, 13, 16}
{"Sarah", 12, 17, 15}
{"Amy", 14, 16, 6}

list<string> alpha_marks =
{
"", // Index = 0 is out of range
"f-", "f", "f+", "e-", "e", "e+", "d-", "d", "d+",
"c-", "c", "c+", "b-", "b", "b+", "a-", "a", "a+"
}

scope school
{
// subjects axiom list is populated directly in the body.
flow<term> report
{
integer english,
integer maths,
integer history
}
(
list<axiom> subjects,
. subjects +=
axiom { subject="English", mark=alpha_marks[english] },
subjects +=
axiom { subject="Math", mark=alpha_marks[maths] },
subjects +=
axiom { subject="History", mark=alpha_marks[history] }
)
}

flow score
{
string student,
export list<axiom> student_marks
}
(
cursor<axiom> subjects =
school.report(english, maths, history)
->subjects,
string report = student,
{
? fact subjects,
report += " " + subjects->subject + ":" + subjects->mark,
subjects++
},
student_marks += axiom { report }
)

query marks(grades : score)