CUATL
CUATL
or your aptitude test you’ll be asked to use a simple, new programming language called
F
CUATL, which contains only a few features compared to more commonly used languages
such as C++ or Python. This document contains everything you need to know about the
language before you take your test. You can check your knowledge by attempting the
sample questions at the end.
Datatypes
C
● UATL has only two datatypes.These areintegersandlistsof integers.
● Integers are always declared with a single letter such asx,y,z,a,b,cetc.
● Lists are always declared by addingsto a variablename, such asxs,ysetc.
○ We can define a list with the - operator, so we might create a list calledxs
with the literal value 1-2-3-4, for example
○ Values can be added to the end of a list with the <- operator, e.g.
■ xs <- 5
■ so 1-2-3 <- 4 is 1-2-3-4
○ We index lists using integers, eg xs1, xs2, xsi
○ Indexes begin at 1, not zero
■ So if xs is 3-4-5 then xs1 is 3 and xs2 is 4
Operators
Control Structures
here is only one kind of loop, which is a for-each style loop iterating over a list. It uses the
T
syntax over(xs)and will iterate over each value inthe xs list, referring to each element as x
in this case. There are no do or while loops. Scope is defined by the braces { and } as in C++
and Java. A simple example might be:
ver(xs)
o
{
x ::: 0
}
x ::: y < 5 ? y , 0
Functions
In addition, we may define functions. Function names always begin with the word ‘do’, apart
from ‘main’, which serves its usual purpose. They may accept parameters in round brackets
and return an integer or nothing at all. We return a value by putting it in quotes. The following
example returns the value t, which is the sum of the elements of the list xs.
oSum(xs)
d
{
t ::: 0
over(xs)
{
t ::: t pl x
}
“t”
}
As a final note, there are no semicolons in CUATL. A statement must occupy a single line.
Practice Questions
ave a go at these questions to make sure you’ve understood how the language works
H
before you take your test. The answers are at the end of the document.
Question 1:
ain()
m
{
x ::: 10
x ::: 11
y ::: x rm 3
}
Question 2:
main()
{
s ::: 1-11-5-2-4
x
b ::: xs2 mi xs3
q ::: b dv xs4
}
Question 3:
ain()
m
{
xs ::: 1-1-1-1
over(xs)
{
x ::: x pl 2
}
z ::: xs4 mu 2
}
Question 4:
oMysteryThings(xs, n)
d
{
c ::: 0
t ::: 0
over(xs)
{
t ::: c < n ? t pl x , t
c ::: c pl 1
}
“t”
}
ain()
m
{
ys ::: 1-2-3-4-5-6-7-8-23-65
f ::: doMysteryThings(ys,4)
}
1. y is 2. x is overwritten in the second line to the value 11. The modulus operation
gives the remainder after dividing 11 by 3, which is 2.
2. q is 3. The value of b is assigned to 6. This is then divided by 2.
3. z is 6. All elements are 3 once the loop has completed. The last element is then
multiplied by 2 to obtain z.
4. f is 10. The function stops adding elements to the total after 4 iterations.