SECTION 15 / 28

Unpack the four returned grade lists

1 min read
The returned outer order is [A-list,B-list,C-list,D-list]. Each extracted component remains a list of IDs.
The returned outer order is [A-list,B-list,C-list,D-list]. Each extracted component remains a list of IDs.
REAL COURSE DATA · SORT, GROUP AND VERIFY

Unpack [A,B,C,D] grade lists

Follow the selected procedure. Change a field, tie rule or weekday and explain why the result changes.

Ready

CURRENT RECORD / VALUE

Ready to begin

No records have been processed. Start with Next step.

What we remember

Processed
0

Predict the next change. Keep track of which list level, field and position convention the procedure uses.

G = SimpleGradeAssignment(SortedMarks)
A = first(G)
B = first(rest(G))
C = last(init(G))
D = last(G)

The grading procedure returns one outer list containing four lists. Its outer length is 4 even though there are 30 IDs across the inner lists. Each inner list can have a different length or be empty. Evaluate nested expressions from the inside out.

first(G) is the complete A-grade list. first(first(G)) would be its first student ID, and is safe only if A is non-empty. last(init(G)) selects the third grade list; it does not automatically select its final student.

Try it yourself

What is the type of first(G)?

Show explained answer

A list of student IDs.

Try it yourself

What is length(G) for this contract?

Show explained answer

4, because the outer result has A, B, C and D components.

Try it yourself

Is first(first(G)) always defined?

Show explained answer

No. The A list might be empty even when G itself contains four lists.

YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑