receive-student-scores2.taq

java -jar taq.jar receive-student-scores2

Running query marks in global scope 
student_marks(report=George english:b+ maths:b- history:a-)
student_marks(report=Sarah english:c+ maths:a history:b+)
student_marks(report=Amy english:b maths:a- history:e+)

Description

receive-student-scores2.taq demonstrates how to return an axiom list from a function call to a template which only has fixed return type of term list. Function “school.report()” converts 3 numeric scores to an axiom list containing subject + alpha mark records. A “subjects” term declares an axiom list which is exported by the “report” flow

list<axiom> subjects

The receiver contains a curosr which binds to a variable named “subjects”

flow school.report(english, maths, history) {

cursor<axiom> subjects,


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

list<string> alpha_mark =
{
"", // 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_mark[english]},
subjects +=
axiom {subject="maths",mark=alpha_mark[maths]},
subjects +=
axiom {subject="history",mark=alpha_mark[history]}
)
}

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

query marks(grades : score)