Way back in section 1.4 you wrote a dfn to convert test scores into letter values.
You were led to produce some function or expression similar to the following:
Grade←{'FDCBA'[+/⍵∘.>80 70 60 50 0]}
Grade 95 65 92 77
This is an array-oriented solution to this problem. However, if a human was manually grading test scores, they might take one scored paper at a time and decide on which letter grade to write by reading each score.
Procedural psuedocode:
scores = 93,85,45,10,70,16,93,63,41,7,95,45,76
For each score in scores:
If score is greater than 80:
Write "A"
Else If score is greater than 70:
Write "B"
Else If score is greater than 60:
Write "C"
Else If score is greater than 50:
Write "D"
Else
Write "F"
Control Structures in Dyalog are keywords beginning with a :
colon.
:If :OrIf :AndIf :ElseIf :Else :EndIf
:For :In :EndFor
:While :EndWhile
:Repeat :Until
Exit from a loop before it is finished using the :Return
keyword.
Translate the pseudocode above into a tradfn called Grade2
using control stuctures.
Rewrite the Grade
function again as either a dfn or a tradfn called Grade3
which uses the interval index function (dyadic ⍸
).
Use the ]runtime
user command to compare the computation time for each of the three grading functions.
]runtime -c "Grade 10×⍳10" "Grade2 10×⍳10" "Grade3 10×⍳10"